本文整理汇总了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