‎03-22-2021 10:18 AM - edited ‎03-22-2021 10:37 AM
Hi,
I have a complex xml file which I need to extract data from. Instead of reverse engineering the data structure or writing a complex text-search-based parser I'm wondering if there is a simple way to import an xml file as a 2D array of strings, like excel does.
For example if you open the xml here: https://www.w3schools.com/xml/simple.xml
in excel then excel does the conversion for you:
UPDATE: the xml has all these joint options which - as far as I understand - means that not all the columns of a given row are stored but some some of them are derived from the previous ones. This makes the reading harder, its not just that I recursively read the child elements / attributes. Also... I could call the excel API, but it is super slow which huge amount of data and the purpose of this project would be to speed up the process by not using excel for the parsing.
Any idea would be appreciated.
Thanks!
(Unfortunately I can't post the file due to IP reasons.)
‎03-22-2021 01:15 PM
LabVIEW's native XML parsing is probably slower!
‎03-23-2021 02:38 AM
This was quite a useless comment as it didn't answer the question at all.
‎03-23-2021 06:40 PM
I have been looking for the same functionality for some time now. Unfortunately, LabVIEW doesn't seem to have a way to automatically interpret your data, even as a simple 2D string array, as a browser or excel would.
LabVIEW has inbuilt VIs to allow you to read XML file data easier, but you do need to have a schema or know what fields you will be looking for.
The example below kind of automates the process a little bit and you could make it smarter, but will still likely be a lot of effort.
C:\Program Files (x86)\National Instruments\LabVIEW 2020\examples\File IO\XML\Parse XML\support
‎03-23-2021 06:59 PM
If you're willing to put in the work to properly parse out the schema instead of looking for a catchall "Make this a 2D string array for me" function, then I would recommend using LabXML instead of the built-in XML parser:
http://labxml.sourceforge.net/
The code was put together in 2005 or so but it still works just fine.
I would note that the problem with the built-in parser is not its speed at reading a single line, it's the fact that it tends to take longer roughly at the square of the file size it reads from. So it reads 100 lines just fine, but when you go to read 1,000 lines, it doesn't take 10 times longer like you would expect, it takes more like 100 times longer.
You will have to learn Xpath syntax though, no matter what sort of parsing you do by yourself:
https://www.w3schools.com/xml/xpath_syntax.asp
‎03-26-2021 08:21 AM
Thanks for the ideas. Instead of reverse engineering the XML I have just processed the file as text... which is not too elegant but works anyways. Too bad that LV doesn't support this type of flattening.