Get Elements By Tag Name and Loop through Nodes : DOM « XML « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » XML » DOMScreenshots 
Get Elements By Tag Name and Loop through Nodes
Get Elements By Tag Name and Loop through Nodes
 
Imports System.Xml
Imports System.Xml.Serialization
Imports System.IO

Public Class MainClass
   Public Shared Sub Main()
        Dim rawData As String = _
            "<Products>" & _
            "  <Product>" & _
            "    <name>Name 1</name>" & _
            "    <Id>101</Id>" & _
            "    <quantity>10</quantity>" & _
            "  </Product>" & _
            "  <Product>" & _
            "    <name>Name 2</name>" & _
            "    <Id>102</Id>" & _
            "    <quantity>10</quantity>" & _
            "  </Product>" & _
            "</Products>"

        Dim xmlDoc As New XmlDocument
        Dim productNodes As XmlNodeList
        Dim productNode As XmlNode
        Dim baseDataNodes As XmlNodeList
        Dim bFirstInRow As Boolean

        xmlDoc.LoadXml(rawData)

        productNodes = xmlDoc.GetElementsByTagName("Product")
        For Each productNode In productNodes
            baseDataNodes = productNode.ChildNodes
            bFirstInRow = True
            For Each baseDataNode As XmlNode In baseDataNodes
                If (bFirstInRowThen
                    bFirstInRow = False
                Else
                    Console.Write(", ")
                End If
                Console.Write(baseDataNode.Name & ": " & baseDataNode.InnerText)
            Next
        Next
   End Sub
End Class



           
         
  
Related examples in the same category
1.Read Xml with XmlDocument and XmlNodeReader
2.Create new node from selected node
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.