08-04-2009 04:34 PM
Solved! Go to Solution.
08-04-2009 05:42 PM
When you say you don't know the content are you referring to the structure of the cluster, or its values? That XML is using the LabVIEW schema. Thus, all you need is the Unflatten From XML function with the appropriate datatype:
If your cluster structure is unknown, you're talking about a whole different ballgame. You would need to try to define the boundaries of the problem, otherwise it's going to be a VERY complicated VI. For example, do you need to extract just the contents of the array? If so, then you just need to get the <Array> node, which is pretty simple.
You will also need to indicate which version of LabVIEW you're using. If you have 8.5 or earlier, then you will need to use third-party tools to read the XML files if you're using your own schema (which it sounds like you're doing). Options include LabXML (free) or JKI's Easy XML (not free). If you have LabVIEW 8.6 then you can use the XML Parser VIs and functions. Of course, you can always simply read it in as a string and simply parse it that way by looking for the node names using Match Pattern.
08-04-2009 06:04 PM
thank you very much. just a quick reply, i'll post more detail tomorrow.
I use 8.6 version. The xml file i'm supposed to read contains clusters which may contain 1D or 2D arrays strings or double. the vi should be able to handle these different cases and put the datas in a csv file.
I think I can make a vi which surf the xml tree and has different subvi to extract different type of data.
what do you think about that?
how can i use the unflatten function if i don't know the type of the data i have to extract?
could you give me an example of the use of match pattern in this case?
thank you very much
08-05-2009 10:15 AM
The Unflatten From XML function requires a datatype wired to it. That was why I asked whether you didn't know the structure or the values, and were just trying to read the values from the XML file.
The LabVIEW XML schema is defined in the LVXMLSchema.xsd file located in the labview\vi.lib\Utility directory. Arrays are indicated using the <Array> node. The <Dimension> node indicated the size of a particular dimension, so having multiple <Dimension> nodes indicate multiple dimensions of an array. The node names that follow the <Dimension> nodes indicate the datatype (<I32>, <DBL>, <String>), so that tells you whether you have an array of integers, floats, or strings.
08-05-2009 10:49 AM
Thank you again,
I'm forwarding my vi draft with many comments and an xml file sample.
Data in cluster is stored according to the LabVIEW schema, infact it is generated by LabVIEW.
What I'm trying to do is to access the element of the cluster and read their content using the Invoke node and Property node functions. Could you give it a look, there may be something wrong, I'm not able to access cluster children.
Which funcions should I use? Could you give me an example? You may use the draft I enclosed...
Then write these data in a csv file should be the easier part.
BODY{font:x-small 'Verdana';margin-right:1.5em} .c{cursor:hand} .b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none} .e{margin-left:1em;text-indent:-1em;margin-right:1em} .k{margin-left:1em;text-indent:-1em;margin-right:1em} .t{color:#990000} .xt{color:#990099} .ns{color:red} .dt{color:green} .m{color:blue} .tx{font-weight:bold} .db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier} .di{font:small Courier} .d{color:blue} .pi{color:blue} .cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888} .ci{font:small Courier;color:#888888} PRE{margin:0px;display:inline}
08-05-2009 11:49 AM
Rather than getting the <section> node you could simply go directly to the <Array> node since that' the one you're really interested in. Basically what it comes down to is to determine how many array elements you have, and this depends on whether you have 1 or 2 <Dimsize> nodes. The rest is just getting child nodes and the next siblings. See attached as a starting point. The attached XML file is for a 2D array (change the extension to .xml).
Notes on example:
08-06-2009 04:06 PM
Amazing solution, you gave me more than a hint!
With the method you suggested I was able to read from a cluster any type of data and write them in a csv with the format I like.
Thank you again, your help has been very precious
02-09-2010 03:28 AM
Hi All,
I have done one VI that will write xml file. I have added that subvi along with the xml file (Labview Ver 7.1).
Please change the .txt extension to .xml since i was not able to attach .xml file.
Now i want to read it back. Kindly tell me how can i read it.
/J
02-09-2010 08:59 AM
You should have really created a new thread since your question doesn't have to do with extracting data from an XML file and exporting to a spreadsheet file.
Since you have your own schema then to read the XML file you have to do the reverse of what you're doing. You may want to consider looking into using LabXML or JKI's Easy XML. I'm not sure if the latter is available for 7.1, though.
02-02-2012 10:21 AM
Thanks,
But I keep receiving all the time the error in the Open File parser, why th?
See attached jpg
Thanks for any hint