Mega Code Archive

 
Categories / ASP.Net Tutorial / XML
 

Display data in XML file recursively (VB net)

<%@ Page Language="VB" %> <%@ Import Namespace="System.Xml" %> <script runat=server>    sub Page_Load(Sender as Object, e as EventArgs)       dim xmldoc as new XMLDocument()                 xmldoc.Load(Server.MapPath("Data.xml"))       ShowTree(xmldoc.DocumentElement)           end sub        sub ShowTree(node as XMLNode)       Dim attrnode As XmlNode       Dim map As XmlNamedNodeMap            If Not(node.HasChildNodes)          output.Text += "<b>" & node.Name & "</b> &lt;" & _             node.Value & "&gt;<br>" & vbcrlf       Else          output.Text += "<b>" & node.Name & "</b>"          If node.NodeType = XmlNodeType.Element Then             map = node.Attributes             For Each attrnode In map                output.Text += " <b>" & attrnode.Name & "</b> &lt;" & _                   attrnode.Value & "&gt; " & vbcrlf             Next          End If          output.Text += "<br>"       End If              If node.HasChildNodes then          node = node.FirstChild          While not IsNothing(node)             ShowTree(node)             node = node.NextSibling          end while       end if    end sub </script> <html><body>    <asp:Label id="output" runat="server" /> </body></html> File: Data.xml <?xml version="1.0"?> <bookstore>   <book genre="asdf">     <title>asdf</title>     <author>       <first-name>asdf</first-name>       <last-name>asdf</last-name>     </author>     <price>asdf</price>   </book>   <book genre="asdf">     <title>asdf</title>     <author>       <first-name>asdf</first-name>       <last-name>asdf</last-name>     </author>     <price>asdf</price>   </book>   <book genre="asdf">     <title>asdf</title>     <author>       <first-name>asdf</first-name>       <last-name>asdf</last-name>     </author>     <price>asdf</price>   </book> </bookstore>