LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with parsing XML

Hello everyone,

 

I have trouble parsing XML in LabVIEW 2017.

My XML-file looks like the following:

<?xml version="1.0" encoding="UTF-8" ?>
<ResultData>
    <Info>
        <Item name="Version">
            <Param name="major" key="88" value="0">major =&gt; application software version major number</Param>
            <Param name="minor" key="89" value="0">minor =&gt; application software version minor number</Param>
        </Item>
        <Item name="Time">
            <Param name="year" key="93" value="2019">year =&gt; application software build year</Param>
            <Param name="month" key="94" value="4">month =&gt; application software build month</Param>
		</Item>
    </Info>
</ResultData>

What I wanna do is to look for the "major" in "Version" and get the following "value".

 

This is what I tried so far:

Unbenannt.PNG

 

I can't figure out what's the correct XPath-Command to accomplish this task.

Mabe there is some XML-expert who can help me!

 

Thanks,

Sylvan

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

Help us to help you.  Instead of making us type the XML File example in ourselves, why don't you save us the time and effort (and encourage us to spend our time helping you) by providing the XML file, yourself?

 

Bob Schor

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

Hi Bob,

 

I thought I did, but it seems the forum doesn't allow .xml extensions. So here it is packed as .zip.

0 Kudos
Message 3 of 9
(2,950 Views)

Not really related to LabVIEW, so not an expert, but maybe:

//.[@name="major"]/@value

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

I think the problem is 2 parts.  First, I think this is the right xpath:

 

/ResultData/Info/Item[@name="Version"]/Param[@name="major"]

 

But after that, if you just use "Get XML" you still don't get just the value.  You need to add more code to search for just the one attribute:

Xpath parsing.PNG

Message 5 of 9
(2,919 Views)

I found this site - https://www.w3schools.com/xml/ - extremely helpful in getting me to think about how to organize my LabVIEW xml parsing.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 6 of 9
(2,915 Views)

I've also found that trying to drill down one level at a time before coding the next level helps a lot.  Parse one level; if you're expecting an array of references, but you get an empty array (or the wrong size), fix it until you get the correct results.  If you're expecting one reference, but you get a reference number of 0, you know you didn't parse correctly.  Go and fix it and then code the next level.

 

Oh, and to keep open references from piling up, always close them explicitly.  It's not a big deal when doing the above procedure because (hopefully) you'll never leave enough references open to cause a significant dip in resources, but you should always clean up after yourself.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 9
(2,909 Views)

I'd test outside LabVIEW, for instance with https://www.freeformatter.com/xpath-tester.html.

 

That was simply the first google hit for "online xml xpath".

 

Or a online xpath generator.

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

I think LabVIEW comes with an xpath example.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 9
(2,888 Views)