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: 

populate XML attributes issue

Solved!
Go to solution

say, I have an XML file such as this one:


<?xml version="1.0"?>

<pdml version="0" creator="me">

<packet>

    <proto name = "geninfo" showname="General Info">

         <field name = "num" value="1" />

         <field name = "len" value="5" />

    </proto>

    <proto name = "data" showname="myData">

         <field name = "data" value="00:0A:0B:0C:0D:0F" />

    </proto>

</packet>

<packet>

    <proto name = "geninfo" showname="General Info">

         <field name = "num" value="2" />

         <field name = "len" value="4" />

    </proto>

    <proto name = "data" showname="myData">

         <field name = "data" value="EF:AA:FB:0C:0D" />

    </proto>

</packet>

 

 


As you can see, I have two packets.  I was able to get Labview to read in a child node array of two but now how do I read in the attribute as an array or collection of record for each "proto" and then obtain the data only.  For example, I would like to retrieve data from packet #2 and it should yield "EF:AA:FB:0C:0D", how do I do this?  I know how to retrieve a simple xml file but getting to the attribute part is a little tricky here.  Thanks

0 Kudos
Message 1 of 4
(2,319 Views)

Not sure exactly how you want to get to the data, but XPath makes it relatively straightforward, just use '@name' to specify an attribute.

 

XPathAttributeExample.png

 

Here you specify the packet number, you could drop the [number] and use Find All Matched Nodes to get an array for all packets as well.

Message 2 of 4
(2,306 Views)

Where can I get that XPath VI, the one with the search icon?  Is this part of LV 8.6 also?

0 Kudos
Message 3 of 4
(2,299 Views)
Solution
Accepted by topic author lavalava

D'Oh!  That one is new for LV9.  Sorry.  Here is a variation using .NET (next you'll tell me you are on a Mac).

 

dotNET XPath.PNG

 

 

0 Kudos
Message 4 of 4
(2,285 Views)