Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Display all node names and values >Thread Next - Re: Display all node names and values Re: Display all node names and valuesTo: NULL Date: 9/3/2007 6:30:00 PM Hi Neil, Thanks for the response. I just typed in the xml data as an example, sorry for the typo... Also, I should have been a bit more clear, I am not looking for an XSLT solution to the problem, rather, I would like to know how to iterate through all nodes using the classes available in Asp.Net, ie: using the XMLDocument and other XML classes provided by the framework, ie: dim xmldoc as XmlDocument xmldoc = new XmlDocument() xmldoc.Load( "datafile.xml" ) ' Now iterate through all the nodes and display the node name and value (if any). Have any code kicking around to do that? Thanks again! "Neil Smith [MVP Digital Media]" wrote: > On Mon, 3 Sep 2007 09:32:00 -0700, Brent D. > <BrentD@d...> wrote: > > >Hello, > > > >Using Asp.Net, does anyone have some sample code that will simply display > >all of the node names and values in an XML file? For example: > > > >XML File: > > > .... Should have the processing instruction > <?xml version="1.0" encoding="utf-8"?> > > Your code will problably be failing because you've cut+pasted > "verision" with an extra 'i' after the 'r' in 'version'. > > > ><?xml verision="1.0" encoding="utf-8"?> > ><root> > > <node1>value 1</node1> > > <list> > > <node2>value 2</node2> > > <node3>value 3</node3> > > </list> > > <node4>value 4</node4> > ></root> > > > >The output would display: > > > >root > > node1 = value 1 > > list > > node2 = value 2 > > node3 = value 3 > > node4 = value4 > > > Using this modified identity template will transform the input example > to the desired output, adding approximate tab characters according to > the present node depth (needs some adjustment, it's late here) : > > > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="text" indent="no" omit-xml-declaration="yes" /> > > <xsl:param name="node_depth" select="0" /> > > <xsl:template match="node()|@*"> > <xsl:value-of select="local-name()" /> > <xsl:if test="text() != ''"> = <xsl:value-of select="text()" > /></xsl:if> > <xsl:text> </xsl:text> > > <xsl:call-template name="add_tab_stops"> > <xsl:with-param name="node_depth" > select="count(ancestor::node())" /> > </xsl:call-template> > > <xsl:apply-templates select="node()|@*"/> > </xsl:template> > > <xsl:template name="add_tab_stops"> > <xsl:param name="node_depth" /> > <xsl:if test="$node_depth > 0"><xsl:text> </xsl:text> > <xsl:call-template name="add_tab_stops"> > <xsl:with-param name="node_depth" > select="$node_depth - 1" /> > </xsl:call-template> > </xsl:if> > </xsl:template> > > </xsl:stylesheet> > > > > > HTH > Cheers - Neil > > > > HTH > Cheers - Neil > ------------------------------------------------ > Digital Media MVP : 2004-2007 > http://mvp.support.microsoft.com/mvpfaqs > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
