LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble getting matched nodes from XML node

Solved!
Go to solution

Hello,

 

Let me start off by saying I am very new to LabVIEW and XMLs so any of this could just be wrong. But what I am trying to do is either read the value of the first child (hit) within the node of interest (instance) or count the number of children of a certain type (hit) within the node of interest (instance) and output that as an integer I can use.

 

I mostly have been trying the latter, however there seems to be a problem when I search for all matched nodes after I have found the first matched node. What I don't get is I looked at the "Parse XML String for Multiple Nodes" example and if I copy and paste the node which I am passing into the Get All Matched Nodes VI, with the same XPath expression, it gives me exactly what I want. From what I understand I am passing in the same data both times, only difference is that in the example it only works off the main document where as in my case I am trying to work of a node taken from the main document.

 

I've attached photos of what the "node of interest" (first instance) looks like and also what my little block diagram looks like. I also attached my VI and the example VI I was talking about. 

 

I also attached the XML and XSD files in .png because they wouldn't let me do .txt. Honestly I don't know if the XSD is doing anything but I made one just in case because I saw other examples that had them.

 

Please let me know if I am dumb.

 

 

Thanks,

Dan

 

 

Hit Count Test.pngFirst Instance XML.png

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

This stuff always gives me headaches.  If you run across any useful info, please post it.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 2 of 9
(2,534 Views)

found this on stack overflow https://stackoverflow.com/questions/43739672/get-specific-xml-element-attributes-in-labview

 

looks I can get what I need by using the attribute identifier (@)

 

running the pictured setup yields the value I was looking for. Still don't get why the other method didn't work though...

 

DAnari_0-1622059211802.png

DAnari_1-1622059230171.png

 

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

Now for some reason when I insert the same code into my full program it no longer works...?

 

DAnari_0-1622060846744.png

 

0 Kudos
Message 4 of 9
(2,504 Views)
Solution
Accepted by topic author DAnari
Hello Dan,
try to force the correct order of execution and close the refnum of the XML-document only after the execution of all other properties and methods on your XML-document.
Regards, Jens
Kudos are welcome...
0 Kudos
Message 5 of 9
(2,492 Views)

Another quick note:

 

LabVIEW's built-in XML parsing does work, but it has scaling problems.  If you parse a file that has 1,000 nodes and a file with 10,000, you'd expect it to take 10x longer, but it doesn't.  It actually takes more like 100x longer.

 

So if you're only dealing with small files like the example, you're fine.  But if you ever want to start parsing large ones, I advise you now to switch to a 3rd party solution.  Despite it coming out in 2005, LabXML still works pretty good and is much faster.  It's what I use on all my XML-using projects now.

Message 6 of 9
(2,482 Views)

Thanks Jens, 

 

I think that was my problem with the last section I posted. I ended up doing this shortly after I posted that and it works great. 

DAnari_0-1622068966384.png

 

I'm still somewhat confused how closing refnums works... would this be the correct way and if you could explain why that would help me understand this stuff a little more.

 

Best,

Dan

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

Thanks I'll have to check this out. My files shouldn't be crazy long but it'll be a living document growing over time to thousands and probably tens of thousands of nodes. I might try to make a new doc every month or so though as well so that may avoid this problem but I'll keep it in mind. Thanks.

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

Hello Dan,

yes that's correct now.

In general: Only close a refnum, if all other underlying objects/dependent references/... have been close before.

Regards, Jens

Kudos are welcome...
Message 9 of 9
(2,391 Views)