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

Hi, Here is my xml doc.

 <?xml version="1.0" encoding="utf-8" ?>
<Cable>
  <Product>
    <Type>FA</Type>
    <Start>1800</Start>
    <Stop>2015</Stop>
    <Mark>1952.5</Mark>
  </Product>
  <Product>
    <Type>FAD</Type>
    <Desp>2.6G</Desp>
    <Start>1880</Start>
    <Stop>2635</Stop>
    <Mark>2635</Mark>
  </Product>
</Cable>

 

I want to use "get the first matched node" vi to locate "FA" node. The I use "Get node text content" vi to get the value "1800". and I also want to get next two node value 2015 and "1952.5". But my VI is not working. I past my vi diagram here. could someone take some time to look at it? Thanks!

 

无标题.png

 

0 Kudos
Message 1 of 7
(3,891 Views)

"not working" as in what?

 

getting different values?

 

And stop with posting pictures.

A real VI of your work what you need to attach.

 

0 Kudos
Message 2 of 7
(3,868 Views)

song403 a écrit :

Hi, Here is my xml doc.

 <?xml version="1.0" encoding="utf-8" ?>
<Cable>
  <Product>
    <Type>FA</Type>
    <Start>1800</Start>
    <Stop>2015</Stop>
    <Mark>1952.5</Mark>
  </Product>
  <Product>
    <Type>FAD</Type>
    <Desp>2.6G</Desp>
    <Start>1880</Start>
    <Stop>2635</Stop>
    <Mark>2635</Mark>
  </Product>
</Cable>

 

I want to use "get the first matched node" vi to locate "FA" node. The I use "Get node text content" vi to get the value "1800". and I also want to get next two node value 2015 and "1952.5". But my VI is not working. I past my vi diagram here. could someone take some time to look at it? Thanks!

 

 


First, there is an empty space in front of <?xml version="1.0" encoding="utf-8" ?> that will make the XML parser generate an error.

 

From what you showed us we cannot know what xpath expression you used with the Match First Node.vi function. FA is already a text node so to match it you should use an xpath expression like //Type[text() = "FA"], this will return a reference to the FA text node. Then you can use this reference with the Get Next Non-Text Sibling to get a ref to the Start node. Continue like this for the Stop and Marker Nodes.

 

One last advice, close the references that you opened.

 

Ben64

 

Message 3 of 7
(3,853 Views)

Hi,

Thanks! I think that your suggestion is correct. But I write my VI according to your instruction. But it is unable to fetch correct value. Could you please check it.

 

0 Kudos
Message 4 of 7
(3,819 Views)
Solution
Accepted by topic author song403

You forgot to add // in front of Type. Close the references when no longer required.

 

Ben64

0 Kudos
Message 6 of 7
(3,791 Views)

yes. I forget //. Thanks!

0 Kudos
Message 7 of 7
(3,765 Views)