Results 1 to 4 of 4

Thread: [RESOLVED] Finding xml nodes using xPath

  1. #1

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Resolved [RESOLVED] Finding xml nodes using xPath

    hi here is a sample from my xml


    Code:
    <jobCodes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    	<job>
    		<RoomID>1</RoomID>
    		<RoomName>Bathroom / Toilet</RoomName>
    		<ComponentID>2</ComponentID>
    		<Componentname>Bath</Componentname>
    		<Description>Renew white mastic seal around bath</Description>
    		<Code>45</Code>
    	</job>
    </jobCodes>
    I have a code passed in querystring. I need to find the correct node based on the code, but then get the details for other nodes.

    Is this the best way to build the xml, or is it better to have code as an attribute at job level?

    Currently I do this

    Code:
     
    Dim Doc As XPathDocument = New XPathDocument("MYfile.xml")
                    Dim Navigator As XPathNavigator
                    Navigator = Doc.CreateNavigator()
                    Dim Iterator As XPathNodeIterator = Navigator.Select("/jobCodes/job/Code[text()='" & Master.SORcode & "']")
                    While Iterator.MoveNext()
                        rblJobs.Items.Add(New ListItem(Iterator.Current.Value, Iterator.Current.Value))
                    End While
    This then binds the radiobuttonlist with the Code as text and value.

    how would I bind other fields such as description.

    First time usign xpath so sorry if this seems stupid

  2. #2

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: Finding xml nodes using xPath

    w3schools says

    /bookstore/book[price>35.00]/title

    "Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00"

    So I tried

    Code:
    Dim Iterator As XPathNodeIterator = Navigator.Select("/jobCodes/job/SoRStemCode[text()='" & Master.Code & "']/Description")

    Although it didnt error it didnt return owt?

  3. #3

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: Finding xml nodes using xPath

    figured it out, my syntax was wrong. Should have been

    Dim Iterator As XPathNodeIterator = Navigator.Select("/jobCodes/job[Code[text()='" & Master.SORcode & "']]/Description")

    If anyone can help me figure out how to do similar butr filtering on two nodes that would be great

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Finding xml nodes using xPath

    Hello there,

    For all things XPath, I highly recommend the following application:

    http://www.bubasoft.net/xpathbuilder/Xpathbuilder2.aspx

    I used it a lot back in the day, and it is very good at what it does.

    Although, based on what you are asking, and the increased usage of LINQ to XML, I think it might be time to give that a try.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width