11-30-2016 01:46 PM
Greetings everyone, as title implies, I have a xml file that I would like to read and process in LabVIEW; in particular, it defines a few hardware inputs and outputs, along with channels and the such. It is formatted in a text code style reminiscent of BASIC or C, something along the lines of:
<Module Name="VECTOR">
<RootName>VECTOR</RootName>
<Module Name="CAN">
<RootName>CAN</RootName>
<Channels NumberOfChannels="1">
<Channel Name="CAN 1">
<RootName>CANboardXL pxi Channel 1</RootName>
<Description>
</Description>
</Channel>
</Channels>
</Module>
<Module Name="VECTOR_TIMERS">
<RootName>VECTOR_TIMERS</RootName>
<Channels NumberOfChannels="1">
<Channel Name="CANboardXL pxi Channel 2_TIMER">
<RootName>CANboardXL pxi Channel 2_TIMER</RootName>
<Description>
</Description>
</Channel>
</Channels>
</Module>
</Module>
Basically, each "module" tag opens for a few submodules, declares channels, subchannels, then ends said module. It is comprehensible enough, but I can't seem to think of a reasonably simple algorythm in LV that can read it. What I would like to do is simple data processing:
-Read the file
-Identify main modules
-Identify submodules specific for said module
-Identify names
It strikes me as something that has most likely been done before so, can anyone point me to a whitepaper, thread or the such? Anyone encountered something like this? Will keep on trying on my own, but any help would be very welcome.
11-30-2016 02:02 PM
Have you tried any of the LabVIEW XML vi's?
Specifically the XML parser?
BTW: The XML VIs are in the File I/O palette.
11-30-2016 03:09 PM
On one level, what you want to do isn't particularly difficult (string manipulation), but on another level, you are talking about parsing a language that has several aspects. One element is a simple "declaration" consisting of "<", Identifier ("Module Name"), "=", Value (""Vector""), and ">". Another, which I'll call <Element>, has the form "<", Identifier ("RootName"), <Element>, "/", Identifier ("RootName"). The interesting thing about the definition of <Element> is that it is recursive, as it includes itself in its definition. [Actually, Element has two possibilities -- it can also be a simple ElementIdentifier, such as "VECTOR"].
You can write recursive routines in LabVIEW (they are called "reentrant"), but if you haven't dealt with recursion before, it is easy to get mixed up. See what the XML parser can do for you.
Bob Schor
12-01-2016 03:06 AM
Its good to go with XML Parser, which will give exact output based on Xpath Query.
12-05-2016 08:59 PM
Thanks everyone, sorry for the radio silence, it's been a heckuva week. So far I'm experimenting with xml pallete, with so far acceptable results, some polishing needed most likely due to inexperience on the usage. Will post if I find something relevant.