LAVA Forums Support This Site Forums RSS Feed

Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topic Start new topic
> Article - Using XML Data in LabVIEW is Hard
Using XML Data in LabVIEW
You cannot see the results of the poll until you have voted. Please login and cast your vote to see the results of this poll.
Total Votes: 74
Guests cannot vote 
Jim Kring
post Jan 22 2008, 02:03 AM
Post #1


Changing the world, one VI at a time.
*****

Grp: Premium Member
Posts: 1543
Joined: 22-October 02
From: San Francisco, CA
Member No.: 17
Using LabVIEW Since:1995
LV:8.2.1 ,8.5 ,7.1.1
United States us_california Nothing Selected


Do you find working with XML data in LabVIEW to be difficult? I sure do, and I've written an article about it here:What XML tools are you using to work with XML data? What tools do you wish you had?

[cross posted]

--------------------
-----------------------------------------------------------------------------------------------------
| Book | OpenG | LAVA | Champion | VIPM | Builder | Blog | JKI |
-----------------------------------------------------------------------------------------------------
Go to the top of the page
+Quote Post
Ad
post Jan 22 2008, 02:03 AM
Post #













Go to the top of the page
Quote Post
jlokanis
post Jan 22 2008, 05:01 AM
Post #2


Very Active
***

Grp: Member
Posts: 70
Joined: 14-June 05
From: Seattle, WA
Member No.: 2411
Using LabVIEW Since:1993
LV:8.5 ,8.20 ,7.1.1
United States Nothing Selected Nothing Selected


I read your article. I agree that to the novice, using XML in LabVIEW is not easy. You do need to understand a lot about XML features, like the schema and namespaces. But it is not impossible and can be a very powerful tool for large and complex data driven applications.
Also, the best way to read and write XML from LabVIEW (in my opinion) is to use the MSXML .NET assemblies. I have tried the XML toolkit from NI as well and find it lacking compared to rolling my own with .NET calls.
I am actually working on a presentation to our local LabVIEW user group about .net and using it to work with XML files. I use XML extensively in my LabVIEW applications, mainly as a universal script format to drive data driven portions of my application.
I have tried many ways of parsing XML within LabVIEW. Given the tree nature of XML, my first method was to use recursion (via VI server) to walk an XML structure and then build a representation in a LabVIEW data structure. The first attempt used an array of clusters with elements to contain the node links and the data at the node. The second version used a Variant tree (via attributes) to construct the tree in the LabVIEW data space. This was a more natural representation of the data but was slow to access (due to the overhead of the variant attribute VIs, I suspect). This was before LVOOP. I understand there are better ways to represent tree structure in LabVIEW using the new OOP features but I have not explored that yet.
Each of these methods required you to then translate the data into a LabVIEW structure (nested arrays of clusters) to make it usable (and the code readable) in the rest of the app.
My current implementation is to parse the schema directly into a LabVIEW data structure consisting of arrays of clusters of arrays of clusters...etc... This is the fastest method so far and goes directly to a structure that can be used in the rest of your application. The downside of this approach is the structure of the schema is directly coded into the LabVIEW parsing VIs. So, if the schema changes, so must your code. For my applications this is usually not a big issue since we design schemas up front that are flexible for the design goal of the application.
However, this certainly is not a good generic solution for LabVIEW and XML. I think the holy grail here is likely some sort of LVOOP implementation that can dynamically traverse an XML file and then build a representation in memory that is simple and clear to access in the rest of the application.
Another approach is to use the .NET interfaces to interact with the XML file 'live' instead of preloading and parsing it into a LabVIEW structure. This may have advantages in some applications, but in my experience I have always wanted the data to be resident in memory and fast to access with standard LabVIEW array and cluster tools.

One caveat with using .NET assemblies to access XML is the confounding documentation (or lack thereof) of how to do this. I have spent many an hour staring at MSDN pages trying to understand how to call or what to call to get the result I wanted. Also, there are some pitfalls to watch out for. For example, if you use the MSXML schema validation methods, you cannot simply close the reference to the XML reader when you are done. Instead you must call the CLOSE method in the XMLValidatingReader and the XMLReader before you close their references. If you don't then the OS will keep a file lock on the XML file until LabVIEW is closed.

Once I complete my presentation I will try to remember to post the PowerPoint and VIs here for other to view. In the meantime, I would be happy to share my code with anyone who is interested.

I also strongly recommend looking at the w3schools website (http://www.w3schools.com/xml/default.asp) to learn more about XML.

Also, the best tool I have found for editing XML and creating schema is XMLSpy. It is not cheap, but it has paid for itself many times over on my projects.

-John

This post has been edited by jlokanis: Jan 22 2008, 05:04 AM

--------------------
-----------------
You mean you still use a keyboard to write your code? How quaint...
Go to the top of the page
+Quote Post
Dirk J.
post Jan 22 2008, 06:01 AM
Post #3


Very Active
***

Grp: Member
Posts: 135
Joined: 21-November 05
From: Amsterdam, the Netherlands
Member No.: 3523
Using LabVIEW Since:2000
LV:8.5 ,7.1.1 ,.
Netherlands hol_friesland Nothing Selected


yup, it's not easy.

I for one have been most comfortable with the MSXML activeX interface.
Nevertheless, I'm currently using a virtual class defining (my most relevent) XML related methods and a couple of child classes which implement these methods.
If I need a very safe-and-simple-backwardscompatible-etc routine, I use my LV-string based childclass which honestly can't do a lot;
most of the time I use the ActiveX implementing childclass; and for some other projects the (presently rudementary) .NET implementing class.

ps: since both the activeX and .Net stuff is "by-reference", I implemented this whole class hierarchy as "by-reference"
Go to the top of the page
+Quote Post
silmaril
post Jan 22 2008, 12:44 PM
Post #4


Very Active
***

Grp: Member
Posts: 77
Joined: 7-March 07
From: Munich
Member No.: 7932
Using LabVIEW Since:2001
LV:8.5 ,8.2.1 ,7.1.1
Germany ger_bavaria Nothing Selected


QUOTE (jlokanis @ Jan 22 2008, 06:01 AM) *
I think the holy grail here is likely some sort of LVOOP implementation that can dynamically traverse an XML file and then build a representation in memory that is simple and clear to access in the rest of the application.

That's exactly what I would like to have!
Sounds great, but I don't know where to start. wacko.gif

--------------------
The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom.
Isaac Asimov
Go to the top of the page
+Quote Post
Eugen Graf
post Jan 22 2008, 01:11 PM
Post #5


Extremely Active
****

Grp: Member
Posts: 283
Joined: 6-February 07
From: Homburg/Germany
Member No.: 7689
Using LabVIEW Since:2004
LV:8.5 ,8.0.1 ,.
Germany Kazakhstan Russia


I use LVs XML Flatten/Unflatten instead of Config File VIs, because it's very easy to use like Flatten/Unflatten binary string, but is readable by user like INI-file.

--------------------
Go to the top of the page
+Quote Post
pdc
post Jan 22 2008, 01:50 PM
Post #6


More Active
**

Grp: Member
Posts: 29
Joined: 2-November 06
Member No.: 6703
Using LabVIEW Since:1997
LV:8.5.1 ,8.2.1 ,6.1
Canada ca_quebec Nothing Selected


I use XML Flatten/Unflatten because it's fast and easy to implement. But we have to deal with the limitation of this method.

For more sophisticated design, we use MSXML. Then, it could be more difficult depend on your XML knowledge.
Go to the top of the page
+Quote Post
Saverio
post Jan 22 2008, 03:52 PM
Post #7


Enough LAVA to be dangerous


Grp: Member
Posts: 4
Joined: 17-October 05
Member No.: 3256
LV:7.1.1
United States Nothing Selected Nothing Selected


One of the options in the poll is LabXML, which is what I use. It inherently uses the MSXML parser, so I'm not sure which poll answer to choose in this case (went for LabXML).

The earlier comment regarding using .NET is interesting because I actually tried to use it and I found it to be abhorently slow, as compared to LabXML. I essentially duplicated the operations that were being performed in LabXML in reading an XML node, so as not to hard-code the schema, as mentioned in the post. I found that the same operation was an order of magnitude slower with the .NET XML interface.
Go to the top of the page
+Quote Post
jzoller
post Jan 22 2008, 04:58 PM
Post #8


More Active
**

Grp: Premium Member
Posts: 47
Joined: 12-October 04
Member No.: 793
Using LabVIEW Since:2002
LV:8.2.1 ,7.1 ,6.0.2
United States us_colorado Nothing Selected


Jim, I couldn't agree more.

From my experience, the internet toolkit XML vi's are hugely inconsistent in their interface and the native LabVIEW schema is brittle to the point of being useless.

I ended up writing a private API based around the MSXML support for XPATH queries, but even it suffers from versioning problems on different machines. I will admit, I didn't investigate the LabXML interface too closely because of its dependency on yet another library (Gnome's libXML2).

Joe Z.
Go to the top of the page
+Quote Post
Gavin Burnell
post Jan 22 2008, 09:19 PM
Post #9


Very Active
***

Grp: Premium Member
Posts: 96
Joined: 21-January 06
From: Leeds, UK
Member No.: 3951
Using LabVIEW Since:1994
LV:8.5.1 ,8.2.1 ,7.1.1
United Kingdom uk_yorkshire Nothing Selected


QUOTE (Saverio @ Jan 22 2008, 03:52 PM) *
One of the options in the poll is LabXML, which is what I use. It inherently uses the MSXML parser, so I'm not sure which poll answer to choose in this case (went for LabXML).


Ummm, I thought the later versions of LabXML used libxml2 - the open source XML parser ? The earlier versions did use the MS XML parser though. It doesn't seem to have had active development for a couple of years - somehow I don't think that's because it's perfect already wink.gif

--------------------
Gavin Burnell
Lecturer and EPSRC Advanced Research Fellow
School Physics and Astronomy
University of Leeds, UK.
Go to the top of the page
+Quote Post
semmel
post Jan 22 2008, 09:31 PM
Post #10


I've come back for more.


Grp: Member
Posts: 2
Joined: 25-January 05
Member No.: 1441
Using LabVIEW Since:2001
LV:8.2.1 ,. ,.
Australia Nothing Selected Nothing Selected


I went down the "cluster of array of cluster of array of ... ... string" approach. It worked, but it was cumbersome.
Go to the top of the page
+Quote Post
mgunning
post Jan 23 2008, 01:07 AM
Post #11


Enough LAVA to be dangerous


Grp: Member
Posts: 4
Joined: 18-May 05
Member No.: 2221
Using LabVIEW Since:1993
LV:8.20 ,. ,.
New Zealand Nothing Selected Nothing Selected


For writing XML files I wrote my own simple Flatten-to-XML VI, which works in a similar way to the OpenG Variant Config File tools. In fact, that is where I got the idea from.
It involves converting a cluster of strings (or cluster of cluster of strings, or array of cluster of strings) to a variant, which is fed to the VI, which then converts it to an XML string. It automatically converts the string names to the XML Tag names, and the string values to the XML element values.

Cheers,
Mark.
Go to the top of the page
+Quote Post
Jim Kring
post Jan 23 2008, 01:31 AM
Post #12


Changing the world, one VI at a time.
*****

Grp: Premium Member
Posts: 1543
Joined: 22-October 02
From: San Francisco, CA
Member No.: 17
Using LabVIEW Since:1995
LV:8.2.1 ,8.5 ,7.1.1
United States us_california Nothing Selected


QUOTE (mgunning @ Jan 22 2008, 05:07 PM) *
For writing XML files I wrote my own simple Flatten-to-XML VI, which works in a similar way to the OpenG Variant Config File tools. In fact, that is where I got the idea from.
It involves converting a cluster of strings (or cluster of cluster of strings, or array of cluster of strings) to a variant, which is fed to the VI, which then converts it to an XML string. It automatically converts the string names to the XML Tag names, and the string values to the XML element values.

Cheers,
Mark.


Bingo.

--------------------
-----------------------------------------------------------------------------------------------------
| Book | OpenG | LAVA | Champion | VIPM | Builder | Blog | JKI |
-----------------------------------------------------------------------------------------------------
Go to the top of the page
+Quote Post
Dirk J.
post Jan 23 2008, 09:23 AM
Post #13


Very Active
***

Grp: Member
Posts: 135
Joined: 21-November 05
From: Amsterdam, the Netherlands
Member No.: 3523
Using LabVIEW Since:2000
LV:8.5 ,7.1.1 ,.
Netherlands hol_friesland Nothing Selected


QUOTE (Jim Kring @ Jan 23 2008, 02:31 AM) *
Bingo.


maybe, but reading from xml is still not trivial.

and yes, the .NET thing is whoofully slow.
Go to the top of the page
+Quote Post
Jim Kring
post Jan 24 2008, 12:14 AM
Post #14


Changing the world, one VI at a time.
*****

Grp: Premium Member
Posts: 1543
Joined: 22-October 02
From: San Francisco, CA
Member No.: 17
Using LabVIEW Since:1995
LV:8.2.1 ,8.5 ,7.1.1
United States us_california Nothing Selected


QUOTE (Dirk J. @ Jan 23 2008, 01:23 AM) *
maybe, but reading from xml is still not trivial.

and yes, the .NET thing is whoofully slow.


Right, it's not trivial. There are a lot of things that can be done to make it much easier. I don't want to let the cat out of the bag, yet, but I've got some ideas that i'll be sharing, soon. wink.gif

--------------------
-----------------------------------------------------------------------------------------------------
| Book | OpenG | LAVA | Champion | VIPM | Builder | Blog | JKI |
-----------------------------------------------------------------------------------------------------
Go to the top of the page
+Quote Post
Phil Duncan
post Jan 24 2008, 01:26 AM
Post #15


More Active
**

Grp: Member
Posts: 46
Joined: 26-April 06
From: Adelaide
Member No.: 4848
Using LabVIEW Since:2002
LV:8.5 ,8.2.1 ,7.1.1
Australia Nothing Selected Nothing Selected


QUOTE (Jim Kring @ Jan 24 2008, 09:44 AM) *
Right, it's not trivial. There are a lot of things that can be done to make it much easier. I don't want to let the cat out of the bag, yet, but I've got some ideas that i'll be sharing, soon. wink.gif


Great Post Jim, I agree completely. I have just about completed a project that uses the native LabVIEW XML schema and found that whilst development time is reduced, the resulting xml data is not very readable by people not familar with LabVIEW terminology. And yes the structure can get quite cumbersome eg. <Cluster><Array><Cluster>.. blah blah</Cluster></Array><Cluster> etc.

I am certainly going to investigate the LabXML and/or MSXML options for future projects. Of course I am eagerly awaiting the release of the cat you mentioned !!

Incidently, I did run into an annoying inconsistancy (bug) converting class data to XML which I will post shortly.

Cheers & Beers
thumbup1.gif beer_mug.gif
Go to the top of the page
+Quote Post

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   3 guy 4870 21st May 2003 - 09:59 PM
Last post by: Mark Hanning-Lee
No New Posts   5 JackHamilton 4585 12th August 2005 - 07:27 AM
Last post by: rolfk
No New Posts   1 seckley 3622 20th December 2002 - 04:36 AM
Last post by: Michael_Aivaliotis
No New Posts   0 Michael_Aivaliotis 3207 20th May 2003 - 09:10 PM
Last post by: Michael_Aivaliotis


2 Pages V   1 2 >
Reply to this topicStart new topic