LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

xml recursive element

Hi

i have a XML file with this structure:

 

<Price>
<Data>20151122</Data>
<Hour>1</Hour>
<CNOR>33,370000</CNOR>
<CSUD>33,370000</CSUD>
<NORD>33,370000</NORD>
</Price>
<Price>
<Data>20151122</Data>
<Hour>2</Hour>
<CNOR>29,190000</CNOR>
<CSUD>29,190000</CSUD>
<NORD>29,190000</NORD>
</Price>
<Price>
<Data>20151122</Data>
<Hour>3</Hour>
<CNOR>28,580000</CNOR>
<CSUD>28,580000</CSUD>
<NORD>28,580000</NORD>
</Price>

 

and so for avery 24 hours.

 

I create the cluster in the correct way, but using GXML library, and parsing XML file, i reach to extract only the first value, i try to define price as an array but it doesn't work. Can i have any suggest to solve this problem?

 

Thanks

0 Kudos
Message 1 of 2
(2,572 Views)

This is a "feature" of XML that you can turn to your advantage.  I don't know which "flavor" of LabVIEW XML you are using, so here's the key question -- when you parse the XML string, you say it returns the "first value", which I assume is the cluster "Price".  Where does it leave the XML string?  Is it ready to parse the next element?

 

If (after parsing and returning the Price Cluster) you have a pointer to the next part of the XML, simply delete the previous sub-string (containing the already-parsed Price cluster) and parse again.  If you do this inside a For loop and wire the Price elements to an output Indexing tunnel, you will build an Array of Price clusters (which is what you want).  You do need some code to tell you when you reach the end of the Price clusters (either because you reach the end of the XML data or because you have other data at the tail end of the string), and force an Exit (without raising an error) from the For loop (use a Conditional Indexing terminal so you don't put this last "past-the-end" element into your Array).

 

I've done this using several LabVIEW XML implementations.  I've frequently encountered cases when I want to write XML "on the fly", as the data are being generated, and before I know how big an array I'll need.  Under those circumstances, I write one array element at a time, and when I go to read it back, and know I've really got an "undeclared array" (since I expect multiple XML elements of the same type here), I do exactly what I described above, read and parse one element at a time, testing that each parse was successful and exiting from my For loop if it was not.  I use a sub-VI that I wrote to do this -- the sub-VI takes the full XML string in and returns the "tail remaining to be parsed" -- this lets me put everything in a While loop (I said "For loop" earlier, but I meant "While", with the XML string in a Shift Register (getting shortened by my sub-VI), with the "Parse Successful" output used both as the conditional for the Indexing tunnel and to keep the While loop "looping".

 

Bob Schor

0 Kudos
Message 2 of 2
(2,541 Views)