05-28-2013 08:12 AM
supposing i have the following xml document:
<head>
<book>
<bookname>zio</bookname>
<author>dan</author>
</book>
<book>
<bookname>the spear warrior</bookname>
<author>britney</author>
</book>
<book>
<bookname>the beard</bookname>
<author>derrick</author>
</book>
</head>
i want to search for the author of the book "the beard" using for example the V.I Get first match of labview to access the the node with value "the beard" and then use Get next sibling V.I and Get node text content to get get the author of this book..so my question is how do i write the xpath expression for Get first match so as to access the node with bookname "the beard" instantyly? am trying to minimise the use of loops because they increase the time duration,..thank you (NB:i dont want to use Get all Matched V.I because it obliges me to use a loop in order to access the name derrick and this increases the time duration for my v.i)
Solved! Go to Solution.
05-28-2013 10:50 AM
I'm not really familiar with Xml queries but I had a similar situation recently and I used the following workaround.
Make bookname an attribute your XML becomes:
<head>
<book bookname="zio">
<author>dan</author>
</book>
<book bookname="the spear warrior">
<author>britney</author>
</book>
<book bookname="the beard">
<author>derrick</author>
</book>
</head>
And the query to obtain derrick is
/head/book[@bookname="the beard"]/author
05-28-2013 04:02 PM - edited 05-28-2013 04:06 PM
Since it's all text, why not use a real quick Match Pattern (or Regular Expression, but you don't need that much power here), see attached.
Cameron
05-28-2013 04:59 PM - edited 05-28-2013 05:02 PM
Too lazy to remove the gratuitous . (current) which started out as .. (parent) when I misread the XML.
05-29-2013 03:01 AM
thank you very much sir,it works right now..i was mainly interested in the part //*[bookname='the beard']/./author and using that in my v.i it works right!! thank very much again
05-29-2013 03:04 AM
thank you didje..unfortunately it didn't work this way,,,but thanks all the same
05-29-2013 03:04 AM
thank you cameround..unfortunately that's not exactly what i wanted,,,but thanks all the same
05-29-2013 03:40 AM
supposing i had the string below,how will the part //*[bookname='the beard']//author modify ?in this case there is a possibility of having more than one head...please explain your reply a little bit..
<project>
<head>
<book bookname="zio">
<author>dan</author>
</book>
<book bookname="the spear warrior">
<author>britney</author>
</book>
<book bookname="the beard">
<author>derrick</author>
</book>
</head>
</project>
05-29-2013 03:53 AM
sorry it was me making a mistake,figured it out,thanks