LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading XML file into a cluster

Hi,

 

This is my first post and I am very new to LabVIEW, having only attended courses 1 and 2.

 

I need to be able to read an XML file (using the LabVIEW schema), and can do so easily with the Read From XML File vi and Unflatten From XML.  The thing is that the structure of the data in the XML file is not yet fully defined, so it would be nice if I did not have to pass a predefined cluster to the 'type' input of the Unflatten From XML function.  It seems to me that the XML file defines the structure of the data completely, so I am unclear why LabVIEW needs to know the type to Unflatten it.

 

I have seen other posts about trying to create a Type Def from a C++ header file, but would have thought that it should be possible to create a cluster or a Type Def from the XML file.

 

Am I missing something here, or am I talking sense?

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

LabVIEW compiles your VI everytime you drop an object. Now to ensure that your cluster has proper data type, it will have to process the string you are passing in.

 

This is not really practical in edit mode right? I think the best solution is to ensure that the cluster is defined right in the beginning.

 

In case your cluster is changing dynamically. You could create a strict type def for your cluster, and to convert your xml files to the new format, you could write a VI that will read the XML using your previously used strict type def cluster and feed it into the new strict type def.

 

Hope this helps.

0 Kudos
Message 2 of 6
(4,207 Views)

Thanks NitinD.  Yes I think you're right, I need to get the cluster defined right.

 

What would be really useful would be a way of creating a Strict Type Def from the XML file somehow.  I have seen other people asking about this, but I have not seen any simple solutions.  If that could be done I could take the XML file that I am given, make the Strict Type Def, then just finish off the code.  Having to manually edit the Strict Type Def every time someone needs to add/change a data item in the XML files sounds very time consuming.

 

Any further thoughts from anyone would be a great help!

0 Kudos
Message 3 of 6
(4,171 Views)

I had similar requirementds. I wanted to use XML and the file format should be robust to future extentions. So I build a library based on LibXML Toolkit which behaves similar to the Configuration File VIs. I can write only basic types (string, path, U32, I32, DBL) but I give for each element a section and key. Section and key are interpreted as XPath so that in contrast to the Config File  VI several nested levels are allowed. Section and Key element form nested XML-Tags. All is based on the Microsoft XML DOM. It works only on windows. But I can use the XPath syntax to find information from the file.

 

Advantageous is that the file strukture is not fixed. E.g. if I write the following data to my XML-file <Image No="1"><xDimension Unit="Pixel">2048</xDimension><yDimension ... ></Image> I can later add the tag "comment". Older program versions can still read the file because they scan only for xDimension and yDimension and do not care about other elements due to the XPath syntax. On the other hand I can try to read the "comment" tag in any file. If its not found I just have to use a default value. Even the order of elements is not important. Only the nesting level counts.

 

This approach is very robust against file extentions. You don't have to convert the file each time you add new contents to the file. And if you select the XML-tags carefully the file is also understood by human readers.

0 Kudos
Message 4 of 6
(4,087 Views)
Thanks Jörn.  I will have a look into XPath.
0 Kudos
Message 5 of 6
(4,060 Views)
see here e.g. for XPath introduction
0 Kudos
Message 6 of 6
(4,056 Views)