|
|
krishna, welcome to codeproject
Take the time to read this handy forum guidelines article[^]. Pay attention to item #6.
led mike
|
|
|
|
|
Hi All,
I have an unformatted xml string text which looks as below
<Value Name="Param1" Length="0" Type="System.Double">3</VALUE> <Value Name="Param2" Length="0" Type="System.Double">2</VALUE>
I want to read values from the above xml text. I have tried it to make it
XmlDocument object but it is giving error as illegal characters exist. Please give me advice how to read values from this text. If posible give me a small code snippet.
Thanks,
Aleem Mohammad.
NIIT technologies
abdul.aleem@niit-tech.com
|
|
|
|
|
This is not XML, therefore your question does not belong in this forum. Do you know why ? Do you know how XML is defined ?
1 - it has one root element
2 - it is case sensitive.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Hi, i need to convert a raw xml file into another xml file using xslt. I have no idea how to achieve the desire output. Can anyone provide an example? Thanks.
Input xml:
<root>
<header>
<row>
<entry>header</entry>
<entry>name1</entry>
<entry>result1</entry>
</row>
<row>
<entry>header</entry>
<entry>name2</entry>
<entry>result2</entry>
<entry>result22</entry>
</row>
<row>
<entry>reading</entry>
<entry>name3</entry>
<entry>result3</entry>
</row>
<row>
<entry>reading</entry>
<entry>name4</entry>
<entry>result4</entry>
<entry>result5</entry>
</row>
</header>
</root>
The final xml will be like this:
<root>
<header>
<row>
<name>name1</name>
<result>result1</result>
</row>
<row>
<name>name2</name>
<result>result2</result>
<result2>result2</result2>
</row>
</header>
<reading>
<row>
<name>name3</name>
<result>result3</result>
</row>
<row>
<name>name4</name>
<result>result4</result>
<value>result5</value>
</row>
</reading>
</root>
<div class="ForumMod">modified on Monday, August 25, 2008 11:25 AM</div>
|
|
|
|
|
Member 4703966 wrote: I have no idea how to achieve the desire output.
Anyone who is a beginner would be in that same situation. Rather than ask someone to do it for you, you should be learning the XML/XSLT technology, that's what a developer does.
Member 4703966 wrote: Can anyone provide an example?
There are many examples on the internet. Try the Top XML site and www.w3schools.com, both have great tutorials with sample/example code.
led mike
|
|
|
|
|
Since you voted my post down I guess that means you don't believe that as a developer you should learn the technology you need to work with.
Ok, good luck.
led mike
|
|
|
|
|
Hi All!
The advice I got from this forum in regards to using copy-of instead of value-of was excellent, my XSL is working almost perfectly, however there is one small problem.
This XSL:
<xsl:template match="/HTML/BODY//B">
<B ID="{@ID}" CLASS="{@CLASS}" TITLE="{@TITLE}" STYLE="{@STYLE}" DIR="{@DIR}" LANG="{@LANG}" ONFOCUS="{@ONFOCUS}" ONBLUR="{@ONBLUR}" ONCLICK="{@ONCLICK}" ONDBLCLICK="{@ONDBLCLICK}" ONMOUSEDOWN="{@ONMOUSEDOWN}" ONMOUSEUP="{@ONMOUSEUP}" ONMOUSEOVER="{@ONMOUSEOVER}" ONMOUSEMOVE="{@ONMOUSEMOVE}" ONMOUSEOUT="{@ONMOUSEOUT}" ONKEYPRESS="{@ONKEYPRESS}" ONKEYDOWN="{@ONKEYDOWN}" ONKEYUP="{@ONKEYUP}">
<xsl:copy-of select="."/>
</B>
</xsl:template>
Produces this output:
<B ONCLICK="" ONDBLCLICK="" ONMOUSEDOWN="" ONMOUSEUP="" ONMOUSEOVER="" ONMOUSEMOVE="" ONMOUSEOUT="" ONKEYPRESS="" ONKEYDOWN="" ONKEYUP="" ID="" CLASS="" TITLE="" STYLE="" DIR="" LANG="">
<B>
Hello World!
</B></B>
From this input:
<B>
Hello World!
</B><BR/>
The B tags are being duplicated due to my use of the "." Xpath syntax, however when I tried "child::*" the text inside all single level tags like:
<B>Hello World!</B>
is not displayed at all.
Can anybody suggest a soloution to this problem.
Thanks!
MrWolfy
|
|
|
|
|
Starting to feel sort of responsible for your project...
I'm not sure what the problem is this time though. What's the overall goal of your transformation?
Do you want to
a) copy all the B and EM tags of some HTML to a self defined XML( or HTML) structure,
or
b) reproduce a complete HTML with all B and EM tags having a set of attributes which may be missing in the original?
When a: what's your target structure?
When b: probably a little recursion is called for.
http://www.xmlplease.com/xsltidentity
might be a good link to start with.
|
|
|
|
|
Hi and Thanks!
Frank... Your help has been fantastic, clear and precise. If not for your help I'd still be trying to copy nodes with value-of .
The article you provided solved my problem completely and was exactly what I was looking for.
However there is just one more little nagging detail.
How would I only output attributes with a value, so that all attributes such as ONCLICK="" will not be displayed?
Thanks for all your help!
MrWolfy
|
|
|
|
|
In the article they suppress the id attributes with the help of a template
<xsl:template match="@id"/>
which matches them but does nothing.
I think you're looking for something like
<xsl:template match="@*[string-length(.)=0]"/>
Haven't tried it out though; could be faulty, but I hope you get the idea.
|
|
|
|
|
Hi and Thanks!
Thanks Frank! Problem solved, that template was just what I needed to complete my project!
Thanks Again!
MrWolfy
|
|
|
|
|
I have XML that I need to tranform to another structure of XML. The XML I need to transform is below:
<ArrayNode>
<Base>
<aa>1</aa>
<bb>text</bb>
<cc>
<ccc>
<cccc>text#1</cccc>
<cccc2>text#1</cccc2>
</ccc>
<ccc>
<cccc>text#2</cccc>
<cccc2>text#2</cccc2>
</ccc>
</cc>
<dd>text</dd>
</Base>
<Base>
<aa>2</aa>
<bb>text2</bb>
<cc>
<ccc>
<cccc>text#3</cccc>
<cccc2>text#3<cccc2>
</ccc>
<dd>text</dd>
</Base>
</ArrayNode>
This needs be tranformed to:
<ArrayNode>
<Base>
<aa></aa>
<bb></bb>
<cc>
<ccc>
<cccc>Text#1</cccc>
<cccc2>Text#1</cccc2>
</ccc>
</cc>
<dd></dd>
</Base>
<Base>
<aa></aa>
<bb></bb>
<cc>
<ccc>
<cccc>Text#2</cccc>
<cccc2>Text#2</cccc2>
</ccc>
</cc>
<dd></dd>
</Base>
<Base>
<aa></aa>
<bb><bb>
<cc>
<ccc>
<cccc>Text#3</cccc>
<cccc2>Text#3<cccc2>
</ccc>
<cc>
<dd></dd>
</Base>
</ArrayNode>
Wherever <ccc> exists, it needs to loop over each <ccc> and insert each individual <ccc> into the rest of the data for that <Base> group. So if there are 3 <ccc>'s, it should repeat the entire <Base> group and insert one of the <ccc> nodes.
Thanks in advance
|
|
|
|
|
Hi All!
After the success of the help I got on my earlier post I have run into another problem.
While all my tags now work anywhere in the document below the BODY tag, my xsl:value-of in my earlier post fails to output any tags below the first one, for instance:
<B>
<EM>
Hello World!
</EM>
</B>
Only Outputs:
<B ONCLICK="" ONDBLCLICK="" ONMOUSEDOWN="" ONMOUSEUP="" ONMOUSEOVER="" ONMOUSEMOVE="" ONMOUSEOUT="" ONKEYPRESS="" ONKEYDOWN="" ONKEYUP="" ID="" CLASS="" TITLE="" STYLE="" DIR="" LANG="">
Hello World!
</B>
The EM Tags are being ignored completely, and when the tags are swapped the B tags are ignored completely.
Does anyone know why this is happening, and if so, can anyone suggest a fix or workaround?
Thanks!
MrWolfy
|
|
|
|
|
Hi All!
It has just occurred to be that my original question could have been put far more simply:
How would I output unescaped HTML tags using the xsl:value-of element, I have tried disable-output-escaping="yes" but the html tags within are just ignored and seemingly not outputted at all.
Thanks!
MrWolfy
|
|
|
|
|
Have you tried copy-of instead of value-of?
|
|
|
|
|
Hi And Thanks!
Thanks Frank! Again you have provided the soloution to a problem I have been grappling with for weeks!
Thanks Again!
MrWolfy
|
|
|
|
|
|
Don't repost your question. You were given reasonable answers on your first post.
debobrata wrote: the source code I got for the XML Notepad from the Codeplex.com is not building.
The project you describe is far to ambitious for a developer that can't even compile an open source project.
led mike
|
|
|
|
|
Hai,
i want to get the attribute names from the xml using xslt...
my xml is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<!-- Edited by XMLSpy® -->
<catalog>
<cd select="true">
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd select="true">
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>
Now i want to get the value select equal to true or false..
Any one help me....
Regards,
Subbu.H
|
|
|
|
|
H.Subbulakshmi wrote: i want to get the attribute names from the xml using xslt
H.Subbulakshmi wrote: Now i want to get the value select equal to true or false..
I don't know what that means but the following XSLT will render the names of all the attributes that have the value true
<xsl:for-each select="//*/@*[.='true']">
<p>
<xsl:value-of select="name()"/>
</p>
</xsl:for-each>
led mike
|
|
|
|
|
Class declaration:
[XmlRoot(Namespace="http://www.example.com/Person")]
class Person
{
[XmlElement(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
Public string Name;
}
Serialized XML using XMLSerializer and XMLSerializerNamespace
<ns0:person xmlns:ns0="http://www.example.com/Person">
<name>Bill</name>
</ns0:person>
</pre>
I am having trouble deserializing above XML and create an instance of Person class with Name property. Also I did not find a way to pass "ns0" namespace prefix to deserialization.
Any help or direction will greatly be appreciated in any .NET compliant language.
|
|
|
|
|
Hi All!
I need to emulate the HTML <B> and <EM> tags complete with all attributes and event handlers for a little project of mine and everything works fine when these elements are seperate, Here's my xsl stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/HTML/BODY/EM">
<EM ID="{@ID}" CLASS="{@CLASS}" TITLE="{@TITLE}" STYLE="{@STYLE}" DIR="{@DIR}" LANG="{@LANG}" ONCLICK="{@ONCLICK}" ONDBLCLICK="{@ONDBLCLICK}" ONMOUSEDOWN="{@ONMOUSEDOWN}" ONMOUSEUP="{@ONMOUSEUP}" ONMOUSEOVER="{@ONMOUSEOVER}" ONMOUSEMOVE="{@ONMOUSEMOVE}" ONMOUSEOUT="{@ONMOUSEOUT}" ONKEYPRESS="{@ONKEYPRESS}" ONKEYDOWN="{@ONKEYDOWN}" ONKEYUP="{@ONKEYUP}"><xsl:value-of select="self::EM"/></EM>
</xsl:template>
<xsl:template match="/HTML/BODY/B">
<B ONCLICK="{@ONCLICK}" ONDBLCLICK="{@ONDBLCLICK}" ONMOUSEDOWN="{@ONMOUSEDOWN}" ONMOUSEUP="{@ONMOUSEUP}" ONMOUSEOVER="{@ONMOUSEOVER}" ONMOUSEMOVE="{@ONMOUSEMOVE}" ONMOUSEOUT="{@ONMOUSEOUT}" ONKEYPRESS="{@ONKEYPRESS}" ONKEYDOWN="{@ONKEYDOWN}" ONKEYUP="{@ONKEYUP}" ID="{@ID}" CLASS="{@CLASS}" TITLE="{@TITLE}" STYLE="{@STYLE}" DIR="{@DIR}" LANG="{@LANG}" ><xsl:value-of select="self::B"/></B>
</xsl:template>
</xsl:stylesheet>
Now this works fine when <B> and <EM> are seperate, however when one tag is inside the other the result is no formatting at all!
The problem is that the match attribute of each xsl:template tag is only neing applied to B and EM tags in the BODY, is there any way I can apply the B and EM templates to the BODY and to all infinetly deeper nesting levels?
Thanks!
MrWolfy
|
|
|
|
|
MrWolfy wrote: the result is no formatting at all!
No formatting in what? A Browser? If so, looking at your XSL isn't helping us at all.
Post the HTML that is not rendering correctly and the browser version you are using.
led mike
|
|
|
|
|
<xsl:template match="/HTML/BODY/descendant::EM">
|
|
|
|