XPathResultType.String : XPath « XML « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » XML » XPathScreenshots 
XPathResultType.String
  
Imports System
Imports System.Xml
Imports System.Xml.XPath

Public Class MainClass

    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.yourname.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.String
                Console.WriteLine(navigator.Evaluate(expression))


        End Select

    End Sub
End Class

'<bookstore xmlns="http://www.yourname.com/books">
'    <book genre="autobiography" publicationdate="1999-12-12" ISBN="1-111111-11-1">
'        <title>A</title>
'        <author>
'            <first-name>X</first-name>
'            <last-name>Y</last-name>
'        </author>
'        <price>8.99</price>
'    </book>
'    <book genre="novel" publicationdate="2000-01-01" ISBN="0-201-63361-2">
'        <title>Java</title>
'        <author>
'            <first-name>Q</first-name>
'            <last-name>Q</last-name>
'        </author>
'        <price>11.99</price>
'    </book>
'    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
'        <title>C#</title>
'        <author>
'            <name>Author</name>
'        </author>
'        <price>9.99</price>
'    </book>
'</bookstore>

   
    
  
Related examples in the same category
1.Use XPath to do a 'select' commandUse XPath to do a 'select' command
2.Using XPathNavigator to select single node
3.XPathResultType.Number
4.XPathResultType.NodeSet
5.XPathResultType.Boolean
6.Use the XPath return type to determine how to process the XPath expression
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.