LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Open and display XML contents

The other thing (easier in some ways) is to save it with the extension .txt (see attached).  [Note added in proof -- No, if you simply rename it as test-ex-em-el.txt and try to attach it, the Forum will reject it, saying "The File Type (text/plain) does not match the extension (which was .txt).  Huh?  So I'll Zip it, which the Original Poster probably has already done ...] 

 

Once you "look at it", you can "deduce" that the contents are a Cluster called "NowTesting" that consists of the following elements:  Clustr "TestInformation" with 5 elements, two Strings, a TimeStamp, a String, and a Path; Cluster Probe Detail with 9 elements; CableOrderInfo, Cluster with a single Path; FTLSettings, Cluster with 11 elements, mix of I32, Dbl, and (possibly an) Enum (or String); and (probable) Cluster of 32 elements, each an Array (?) with names like Element001, ... Element032.

 

There is no specific identification within the file itself to help define these items as LabVIEW elements (as I have done, above).  There are several LabVIEW-"compliant" XML formulations (Native LabVIEW XML, JKI EasyXML, GXML from the LabVIEW Tools Network) that use differing "rules" to parse XML into LabVIEW, so with a little work, you could add the "syntactic sugar" needed to turn this XML file into a format compatible with one of them.  I have used a few of these, and think this task (adding "sugar") isn't too difficult ...  In particular, for the current file, it should be fairly simple to accomplish "by hand" ...

 

Bob Schor

0 Kudos
Message 11 of 35
(1,380 Views)

It also depends on how you want to use the XML file.

 

You can load it, and then use it like a sort of database. Then I'd go for something flexible, like the native LabVIEW XML parser. You can use XQuery (or XPath?) to get anything from the 'database', and that can be very convenient.

 

If you want to use it to get the data (at the start of your application), convert it so something native, and then optionally save it back, some of the other options might be easier.

 

And it also depends on the (future) data. If the format is going to be a strict format, or if it's going to be flexible and will it change a lot? It's also possible that the (future) XML is highly recursive... Also a factor.

0 Kudos
Message 12 of 35
(1,377 Views)

Ugh.  Native XML parsing is so SLOOOOOOWWWW.  Read Parsing XML is too slow, or is it?  (And read my comment near the bottom.)  The libraries presented there are a bit cumbersome, but the tradeoff for performance is worth it if you need it.  It's quite literally orders of magnitude faster than the native xml vis.

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 13 of 35
(1,369 Views)

@billko wrote:

 It's quite literally orders of magnitude faster than the native xml vis.


Actually, literally, it's more then one, less then two orders of magnitude faster (87 vs 4). So orders of magnitude is not literally correct. Smiley Wink

 

Still impressive of course.

 

There are downsides. I think the XML parser is supported on all CPU based targets? Even RT? LabXML would probably require a cross compile of the dll for that.

0 Kudos
Message 14 of 35
(1,362 Views)

wiebe@CARYA wrote:

@billko wrote:

 It's quite literally orders of magnitude faster than the native xml vis.


Actually, literally, it's more then one, less then two orders of magnitude faster (87 vs 4). So orders of magnitude is not literally correct. Smiley Wink

 

Still impressive of course.

 

There are downsides. I think the XML parser is supported on all CPU based targets? Even RT? LabXML would probably require a cross compile of the dll for that.


For me it was 340x faster, so it is literally orders of magnitude faster.  For me, at least.  😉

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 15 of 35
(1,359 Views)

Bob, If this XML file is extracted from a cluster, is there a way to turn it back into a cluster? That, would be super! 

 

I will install Easy XML and explore.

 

Thanks to all for the excellent feedback! - John

0 Kudos
Message 16 of 35
(1,351 Views)

Management is not willing to pay for EasyXML... Is there a free XML toolkit? When I search  the web for "native XML parser LabVIEW" I don't get any hits from Google that lead to a resource page. Does anyone have a link to a main page that can get me started on the native XML parser? Also, I have a hunch that the "Read From XML File" VI that I am using is part of the Native XML parser? If it is part of the Native XML parser, and the native XML parser has a required schema, am I stuck? 

 

Bob says, "...with a little work, you could add the "syntactic sugar" needed to turn this XML file into a format compatible with one of them ." Bob, is there a reference I can read that tells me how to edit my XML? 

 

Thanks again! -  John 

0 Kudos
Message 17 of 35
(1,339 Views)

There are two palettes for XML in LV:  LV Schema VIs and XML Parser VIs.  "Read From XML File" is part of the LV Schema VIs and these won't work for you (without some XSLT voodoo I have done but wouldn't recommend).  The other palette contains the Load From XML.vi which is what you are going to want.

 

Now, what is it you really want to do with the XML data?  Do you need all values, or just some?  Are you modifying the XML or just reading it?

0 Kudos
Message 18 of 35
(1,333 Views)

Darin,

The XML file is created by a LabVIEW VI. The format of the XML goes back several years. I am updating a data processing application written in VB6 which reads select data items from this XML, computes values of interest, and uses these values to determine a pass/fail status. 

 

I don't wish to modify the XML, unless I must.

 

The values at the end of the XML which are set off my <element001>, <element002>... <element032> are voltage measurements. Other values of interest are the test parameters such as, <Gain> .

 

The new VI I am making will result in a PDF test report.

 

Thanks for your help! -  John

0 Kudos
Message 19 of 35
(1,329 Views)

In your future XML adventures, remember that values like sequence number are better as attributes than part of the tag name, so you should have 32 Element tags with an index attribute of 1-32 instead of Element001..Element032 tags.  That ship has sailed on this project.

 

For a fixed schema and no desire to modify the XML I would simply start with a simple parsing VI that examines all nodes, decides by its name if it is interesting, and if so converts to the proper datatype and puts it into a cluster.

 

ParseXMLtoCluster.png

 

I did not want to deal with posting a typedef, but the first thing you should do is make the constant a TypeDef and then as you decide you want a new value or two from the file you can easily modify the cluster.

 

 

0 Kudos
Message 20 of 35
(1,322 Views)