From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to search for a text node with a particular value in an xml document with labview

Solved!
Go to solution

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)

 

0 Kudos
Message 1 of 9
(2,609 Views)

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

 

 

0 Kudos
Message 2 of 9
(2,595 Views)

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

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 3 of 9
(2,582 Views)
Solution
Accepted by topic author alpony01

XPathExample01.png

 

Too lazy to remove the gratuitous . (current) which started out as .. (parent) when I misread the XML. 

0 Kudos
Message 4 of 9
(2,574 Views)

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

 

0 Kudos
Message 5 of 9
(2,558 Views)

thank you didje..unfortunately it didn't work this way,,,but thanks all the same

 

0 Kudos
Message 6 of 9
(2,555 Views)

thank you cameround..unfortunately that's not exactly what i wanted,,,but thanks all the same

0 Kudos
Message 7 of 9
(2,554 Views)

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>

0 Kudos
Message 8 of 9
(2,549 Views)

sorry it was me making a mistake,figured it out,thanks

0 Kudos
Message 9 of 9
(2,545 Views)