本文整理匯總了VB.NET中System.Xml.XPath.XPathExpression類的典型用法代碼示例。如果您正苦於以下問題:VB.NET XPathExpression類的具體用法?VB.NET XPathExpression怎麽用?VB.NET XPathExpression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了XPathExpression類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: XPathExpressionExample
' 導入命名空間
Imports System.Xml
Imports System.Xml.XPath
Public Class XPathExpressionExample
Public Shared Sub Main()
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()
Dim expression1 As XPathExpression = XPathExpression.Compile(".//bk:price/text()*10") ' Returns a number.
Dim expression2 As XPathExpression = XPathExpression.Compile("bk:bookstore/bk:book/bk:price") ' Returns a nodeset.
Dim manager As XmlNamespaceManager = New XmlNamespaceManager(navigator.NameTable)
manager.AddNamespace("bk", "http://www.contoso.com/books")
expression1.SetContext(manager)
expression2.SetContext(manager)
Evaluate(expression1, navigator)
Evaluate(expression2, navigator)
End Sub
Public Shared Sub Evaluate(ByVal expression As XPathExpression, ByVal navigator As XPathNavigator)
Select Case expression.ReturnType
Case XPathResultType.Number
Console.WriteLine(navigator.Evaluate(expression))
Exit Sub
Case XPathResultType.NodeSet
Dim nodes As XPathNodeIterator = navigator.Select(expression)
While nodes.MoveNext()
Console.WriteLine(nodes.Current.ToString())
End While
Case XPathResultType.Boolean
If CType(navigator.Evaluate(expression), Boolean) Then
Console.WriteLine("True!")
End If
Case XPathResultType.String
Console.WriteLine(navigator.Evaluate(expression))
End Select
End Sub
End Class