05-26-2021 01:56 PM
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
Solved! Go to Solution.
05-26-2021 02:41 PM
This stuff always gives me headaches. If you run across any useful info, please post it.
05-26-2021 03:01 PM
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...
05-26-2021 03:27 PM
Now for some reason when I insert the same code into my full program it no longer works...?
05-26-2021 04:16 PM
05-26-2021 05:23 PM
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.
05-26-2021 05:44 PM
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.
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
05-26-2021 05:47 PM
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.
05-27-2021 02:56 AM
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