本文整理汇总了VB.NET中System.Xml.XPath.XPathExpression.ReturnType属性的典型用法代码示例。如果您正苦于以下问题:VB.NET XPathExpression.ReturnType属性的具体用法?VB.NET XPathExpression.ReturnType怎么用?VB.NET XPathExpression.ReturnType使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Xml.XPath.XPathExpression
的用法示例。
在下文中一共展示了XPathExpression.ReturnType属性的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