Display data in XML file recursively (VB.net) : XmlNode « XML « ASP.NET Tutorial






<%@ 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>








25.11.XmlNode
25.11.1.Display data in XML file recursively (VB.net)
25.11.2.Load data from XML
25.11.3.MoveToNextAttribute