retrungin values with xpath queries question

  • 14 years ago

    I had a question about using xpath queries to find specific data in an xml
    Xml Document.

    Say I had this for an xml document

    <?xml version='1.0'?>
    <!-- This file represents a fragment of a book store inventory database -->
    <bookstore>
      <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
          <firstname>Benjamin</firstname>
          <lastname>Franklin</lastname>
        </author>
        <price>8.99</price>
      </book>
      <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
          <firstname>Herman</firstname>
          <lastname>Melville</lastname>
        </author>
        <price>11.99</price>
      </book>
      <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
          <firstname>Plato</firstname>
          <lastname></lastname>
        </author>
        <price>9.99</price>
      </book>
    </bookstore>

    And I want to retreive the data that is in the firstname and
    lastname nodes.

    Now if I have a code like this:

    Dim first As String
    Dim last As String

    Dim Doc As XPathDocument = New XPathDocument("books.xml")
    Dim Navigator As XPathNavigator
    Navigator = Doc.CreateNavigator()
    Dim Iterator As XPathNodeIterator = Navigator.Select("/bookstore/book/author")
    While Iterator.MoveNext()
    If something happens here
        
    End While

    How do I say if the node name is equal to firstname then first
    equal to the value in firstname.

    I am using vb.net 2005 by the way.

























































Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only 3 numbers of interest to a computer scientist: 1, 0 and infinity”