LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XML parsing (excel like)

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:

 

1984_0-1616426190416.png

 

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.)

0 Kudos
Message 1 of 6
(1,811 Views)

LabVIEW's native XML parsing is probably slower!

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 2 of 6
(1,756 Views)

This was quite a useless comment as it didn't answer the question at all.

0 Kudos
Message 3 of 6
(1,712 Views)

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

0 Kudos
Message 4 of 6
(1,697 Views)

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

 

0 Kudos
Message 5 of 6
(1,694 Views)

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.

0 Kudos
Message 6 of 6
(1,678 Views)