[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
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?
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
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