LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create a file xml as a GXML scheme is possibile?

I have some confusion how to create a xml file custom and open it using GXML library.

In particular i have to create a descriptor of  some blocks with different hierarchical fields, attribute, parents and child.

Is possibile to make it and is there a document that explain how to crete this file following a labview scheme?

I would using GXML library to open and read this file.

Thanks in advance Michele 

0 Kudos
Message 1 of 15
(3,091 Views)

The GXML AddOn has a folder called "Examples" that includes "Generate GXML" that constructs an XML file from a fairly complex LabVIEW Control, a Cluster that includes Arrays of Clusters, multiple file types including TimeStamps, Paths, numbers, booleans.

 

I use it, and like it.  It seems (to me) the easiest way to "map" LabVIEW Data Structures into XML, while retaining a reasonably easy "human-readable" syntax.

 

Bob Schor

0 Kudos
Message 2 of 15
(3,082 Views)

Hi Bob, thank you for the suggestion, but if i have the necessity to read different blocks from a file (i know the scheme of each block and it is equal for all, but i don't know how many blocks are there in the file ) according to a certain scheme (for example the cluster in the the example)

Do you know if is it possibile to call the vi "search parser" recursively or how is possibile to create from parser an array of cluster? Thanks Michele  

0 Kudos
Message 3 of 15
(3,066 Views)

Almost all things are possible with GXML, with a little work.  As near as I can tell, the LabVIEW XML schemas (including LabVIEW XML, EasyXML from JKI, and GXML) all appear to use the premise that an XML File is created by a single "Write Everything and Close the File" operation, and is read by a single "Read Everything and Close the File".

 

Where you have all the data "in hand" and can do a singular Write (or Read), this can work just fine.  However, I (and, I suspect, you) wanted to use it to save records from an Experiment that had "Trials" that took place over an extended period of time, and wanted to write these records one-at-a-time, as they occurred, rather than accumulating them in memory until the end of the Experiment and then doing an "all-at-once" Write.

  • All-at-once:  I can write an "Array of Clusters", as I know how many Array elements there are, but I need to hold them all in memory, so lose everything if there is a program failure, which almost-never-happens, of course.
  • One-at-a-time:  Can write as data occur, not worry about the count, and in event of a program failure, need only to close the file properly.

So that's the "Write" problem.  How about the Read issue?

 

I think GXML does a "Read Everything into a String, then allow User to Parse the Data They Need".  GXML's Search Parser will find the Element you seek and return it to you.  In the example discussed above, where we want to repetetively write a particular LabVIEW Element, such as a Cluster, an unknown number of times, and so write N Cluster records instead of a single "Array of N Clusters" record, we can still accomplish our goal -- simply call the Search Parser asking for one Cluster.

 

Of course, it will eventually reach the end of the Cluster records, and the Parser will fail.  But that's OK -- when it fails, it generates Error 537525, which you can "trap" and use in a While Loop to extract each Cluster and assemble them in to an Array of Clusters (which is, indeed, what the XML represents, just written out one element at a time).  Here's the basic idea:

Parse GXML.png

The XML string is passed in to the Shift Register, where each pass through the While Loop, one "Excel Cluster" is extracted using the Search Parser with the Cluster as the search element.  The sub-VI "Missing Tag?" checks the Error Line and returns both "Tag Found" (the right-hand output), used to add the "good Cluster" to the Array of Clusters, and "Tag Missing" (the bottom output) used to stop the While Loop.

 

Bob Schor

0 Kudos
Message 4 of 15
(3,054 Views)

Hi Bob, thank you, my purpose is little different. I have the necessity to realize a tool for debug some software blocks that they have a descriptor static file for the single elements. (For example  the characteristics could be : type, In/out, format). This file will be generate with an external tool and i have generate it with a syntax that will interpretate with GXML library. So i don't have the necessity to add element dynamically, but i have only the necessity to scan the file xml and extract a single object and i would use the GXML library to read it. Your sincerely Michele     

0 Kudos
Message 5 of 15
(3,050 Views)

Hi Bob, thank you, my purpose is little different. I have the necessity to realize a tool for debug some software blocks that they have a descriptor static file for the single elements. (For example  the characteristics could be : type, In/out, format). This file will be generate with an external tool and i have generate it with a syntax that will be interpretate with GXML library. So i don't have the necessity to add element dynamically, but i have only the necessity to scan the file xml and extract a single object and i would use the GXML library to read it.

I attach an example of xml file create with syntax labview, is possibile to use the GXML and how would be the cluster to pass to the GXML block? thank you

Your sincerely Michele     

0 Kudos
Message 6 of 15
(3,044 Views)

OK, I see your problem!  When I look at the FBlockDescription you attached as an XML file, I see that you have written a Cluster, ClimatelLibrary, that has three elements:  CompatibilityList (Array), Version, and FuncBlockList (Array of Clusters).  However, in the FuncBlockList, the Clusters are not all the same, which defies the LabVIEW Rule that all elements of an Array must be of the same Type.  The first FuncBlock is a Cluster of 6 elements, while the second is a Cluster of 5 (it has no LinkArea element).

 

How did you create this file?  I'm guessing that you did not have a ClimatelLibrary Cluster that you filled and then wrote "all at once", right?  

 

[You might notice that I'm writing "ClimatelLibrary", with two "L"s, "lL" in the middle of it.  In fact, I called the Cluster "ClimateLibrary", and the GXML Parser promptly flagged an error as I didn't use the name that was in the file!  Tag names are very important.]

 

You can, in fact, parse this, but you are going to have to do a lot of the work yourself, knowing the structure of your Data Element.  Basically what you would need to do is something like doing a recursive descent through the XML, identifying the next Tag and deciding where it fits in your Data scheme, reading the Element and saving it appropriately.  For example, when parsing FuncBlocksList (I missed the "s" there, another Tag error), you would start parsing the FuncBlock cluster, ignoring the number of elements, but as you found each element, you would set its value, leaving the values of the "missing" elements at the default value.  Notice also that LinkArea, a Cluster with 2 elements, only has one, LinkElementList, defined in this XML file.

 

I think the problem would be easier to solve by looking at the code generating the XML.  This doesn't seem to be the same kind of problem I described earlier, namely where you have an Array of Elements (such as Clusters) that you want to write out, one at a time, without knowing in advance how many there are -- there we could finesse the issue by reading elements until there were no more (signified by an Error), and let LabVIEW build the Array for us.

 

Bob Schor

 

 

0 Kudos
Message 7 of 15
(3,037 Views)

Hi Bob and than you verry much for the answer, i create this XML file manually. You told me that the Cluster and array must be of the same type and dimension. So i don't know how is possibile to use GXML library to read it. Did you tell me  that i couldn't use the GXML library to read it and i have to use the elementary XML block labview (and not GXML with cluster) to extract the information, doesn't it? If not, kindly, could you show me an example how could i parser my xml file?

Sorry, but I don't understand if to read this file i could, or no, use the gxml and cluster or. 

Thanks Your sincerely Michele 

0 Kudos
Message 8 of 15
(3,025 Views)

The issue with reading any file, even a plain Ascii text file, is you need to know something about the data that are being written.  With text, it "seems simple" since it is "human-readable".  Contrast this with so-called "binary files" where you absolutely need to know what data are written and in which order.  For example, here is a Cluster of a String, an array of 5 I32 Integers, and a "Cluster-of-Clusters" containing 6 Dbls:

Test Cluster.png

If I tell LabVIEW to write this to a Binary file, and take the default setting of pre-pending String and Array lengths, I get the following:  a 4-byte String length (15), the string "This is a test.", a 4-byte Array length (5), 5 4-byte values representing 1 through 5, then 6 8-byte values representing 3 Dbls of 0 and 3 Dbls of 1.  If I'm going to read these data and place them into the Cluster, I need to explicitly know how to read (and parse) the data.

 

Same with XML.  When you write a LabVIEW Variable in XML, you (implicitly or explicitly) write supplemental information that allows LabVIEW to re-format it for you into the appropriate LabVIEW Variable without you doing "all the work yourself".  It gets the information as to the Parsing from the XML Structure, and assumes this matches the structure of the LabVIEW Variable.  

 

In the attachments you provided, the XML file did not match the structure of your Cluster, hence it could not (easily) parse.  The easiest way to "fix" this issue, particularly if you have not yet collected all of your data (and especially true if you have collected almost no data) is to rewrite the routines that generate the XML files.

 

Bob Schor

 

 

0 Kudos
Message 9 of 15
(3,014 Views)

Now, i fix the xml file, my last step will be to transform it into an array of this cluster and i can not make it. thanks Michele 

0 Kudos
Message 10 of 15
(3,012 Views)