XmlDocument.SelectNodes : XmlDocument « System.Xml « VB.Net by API






XmlDocument.SelectNodes

  


public class Test
   public Shared Sub Main
        Dim myDoc As New Xml.XmlDocument
        myDoc.Load("test.xml")

        Dim chpts As Xml.XmlNodeList = myDoc.SelectNodes("/book/chapters/chapter")
        For Each nd As Xml.XmlNode In chpts
            Console.WriteLine(nd.Attributes("id").Value)

        Next


        Dim book As Xml.XmlElement
        book = myDoc.Item("book")
        Console.WriteLine("ISBN: " & book.Attributes("isbn").Value)

        Dim title As Xml.XmlElement
        title = book.Item("title")
        Console.WriteLine(title.InnerText)

        Console.WriteLine("Authors:")
        Dim authors As Xml.XmlElement
        authors = book.Item("authors")

        For Each node As Xml.XmlNode In authors.ChildNodes
            If node.Name = "author" Then
                Console.WriteLine(node.InnerText)
            End If
        Next

        Dim chapters As Xml.XmlElement
        chapters = book.Item("chapters")

        For Each node As Xml.XmlNode In chapters.ChildNodes
            If node.Name = "chapter" Then
                Console.WriteLine(node.Attributes("id").Value)
                Console.WriteLine(node.Attributes("topic").Value)
            End If
        Next
   End Sub
End class

   
    
  








Related examples in the same category

1.XmlDocument.AppendChild
2.XmlDocument.CreateAttribute
3.XmlDocument.CreateComment
4.XmlDocument.CreateElement
5.XmlDocument.CreateNavigator
6.XmlDocument.CreateXmlDeclaration
7.XmlDocument.GetElementsByTagName
8.XmlDocument.LoadXml