Selecting node by XPath : XPath « XML LINQ « VB.Net






Selecting node by XPath

   
Public Class MainClass


    Shared Sub Main()
        Dim file As String = "books.xml"
        Dim doc As New System.Xml.XmlDocument
        doc.Load(file)
        Dim nodes As System.Xml.XmlNodeList
        nodes = doc.SelectNodes("shelf/book")

        Dim counter = 0
        Do Until counter = nodes.Count
            System.Console.WriteLine(nodes.Item(counter).SelectSingleNode("title").InnerText & " by " & nodes.Item(counter).SelectSingleNode("author").InnerText & vbCrLf)
            counter = counter + 1
        Loop

    End Sub

End Class

   
    
    
  








Related examples in the same category

1.Loop through the query results and display the information to the screen.
2.Use XPath to get the tasks for each employee.
3.Evaluates an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.
4.Selects a collection of elements using an XPath expression.
5.XPathExpression Class provides a typed class that represents a compiled XPath expression.
6.Selects a collection of elements using an XPath expression.