Use XPath to do a 'select' command : XPath « XML « VB.Net






Use XPath to do a 'select' command

Use XPath to do a 'select' command
  
Imports System
Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Data


Public Class MainClass
    
    Shared Sub Main()
        Dim XDoc As New XmlDocument()
        XDoc.Load("book.xml")

        Dim XNodes As XmlNodeList
        XNodes = XDoc.DocumentElement.SelectNodes( _
                                  "//Book[starts-with(@Name, 'C#')]/Order")
        Console.WriteLine("Found {0} Nodes", XNodes.Count)

        Dim XNode As XmlNode
        For Each XNode In XNodes
            Console.WriteLine("Book {0} ordered {1} {2}", _
                     XNode.ParentNode.Attributes.GetNamedItem("Name").Value, _
                     XNode.Attributes.GetNamedItem("Quantity").Value, _
                     XNode.InnerText)
        Next             
    End Sub
End Class



           
         
    
  








Related examples in the same category

1.Using XPathNavigator to select single node
2.XPathResultType.Number
3.XPathResultType.NodeSet
4.XPathResultType.Boolean
5.XPathResultType.String
6.Use the XPath return type to determine how to process the XPath expression