04-11-2025 03:35 PM
Hello,
I am starting learning Labview and I would like to know how to extract data from XML file in Labview.
I watched videos on how to do it but they are done on old Labview version, i am on Labview 2020 and i cannot do it like this way.
i have juste this XML code in .XML :
<Cluster>
<Name>Sensor</Name>
</Cluster>
I made this piece of code on labview but have this error
could you please give me advice ?
Thank you
04-11-2025 04:00 PM
There a lot more involved in parsing an XML file that you have there.
Search Help for examples (Find Examples under Help) using XML as the search term.
Take a close look at the example "Load XML with Parser API.vi"
04-12-2025 04:11 AM
Thanks for you reply.
I put my VI into the folder 'support' and i renamed it to TestConfiguration.xml, when I run the VI load XML I have always :
Error -2628 occurred at Invoke Node in NI_XML.lvlib:Load XML File.vi->Load XML with Parser API.vi, even I choosed Valid
04-12-2025 09:51 AM
The LabVIEW Tools Network has several implementations of XML, in addition to the one that ships with LabVIEW. I've had occasion (15 years ago) to experiment with two of them -- EasyXML (JKI) and NI GXML (NI Tools Network).
I ended up using GXML, but made some modifications that "enhanced" it for the purpose I needed. I wanted a flexible data format for recording "behavioral data", where there was a set of "header" information that you knew at the start of the study, a bunch of "time-series" data where you recorded "events" (usually represented by a cluster of entries describing the parameters of a stimulus and the parameters of a response), and a "trailer" section which may have nothing more than the time the study ended. At the time, the XML "model" didn't seem to support writing Array structure one entry at a time, but since GXML had fairly-understandable source code, I "enhanced" the Array structure to put off writing the "end Array" tag until I was done.
The key to using XML is to understand the "rules" for how the data are structured by XML What is the "Shape of your Data"? How do you want to "tag" your data elements for XML? Are you basically trying to read existing XML documents or, like my case, are you looking to structure and write existing (or evolving) LabVIEW Data to an XML document?
Give us an idea of the data structure you envision. If you can do it in XML, that's fine, but you can also simply be "descriptive". And if you have LabVIEW code that does or doesn't work, please attach it (in a LabVIEW Version, like 2021, that most of the experienced Forum users can open). [It's a peculiarity of LabVIEW that the most of the people on the Forum using the latest version are students learning LabVIEW].
Bob Schor
04-13-2025 10:18 AM
As a suggestion to help us help you, please attach either (best) the XML file you are hoping to parse into variables that LabVIEW can recognize (including possibly Clusters and Arrays), or (better) a "disguised" version of the XML file you want to parse, with elements renamed but none of the XML "elements" removed, or (OK, but possibly not exhibiting the problem, if "data-driven") a "dummy" XML file that has as many of the elements of your actual XML file as you feel like including, with "fake" entries and element names.
It might well be that the problem is your XML structure does not parse correctly because it is not "formed" properly. Let us take a crack at turning it into LabVIEW variables, because if we succeed, we will have solved the problem you are having.
Bob Schor
P.S. -- I haven't used XML with LabVIEW in more than a decade, but earlier Projects initially used JKI's EasyXML but later I switched to NI GXML, both found (along with newer versions) in the LabVIEW Tools Network (VIPM).
04-14-2025 07:49 AM - edited 04-14-2025 07:50 AM
If you start from the other direction, with Flatten to XML, you can enter a cluster and see what LV generates. Your file must adhere to that structure.
e.g. an empty Error Cluster through Flatten to XML gives this output:
<Cluster>
<Name>error in (no error)</Name>
<NumElts>3</NumElts>
<Boolean>
<Name>status</Name>
<Val>0</Val>
</Boolean>
<I32>
<Name>code</Name>
<Val>0</Val>
</I32>
<String>
<Name>source</Name>
<Val></Val>
</String>
</Cluster>