LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to read XML file using labview 2017

Hello Everyone,

 

Im trying to read an XML file and to bring the data into an array. Well, I've tried many ways which was not helping me till now. Kindly someone plz suggest to read an XML file.

 

XML file will have a customized data which we required for our project. Hence I cant share that file.

Thanks in Advance.

 

Regards,

Vijay

0 Kudos
Message 1 of 7
(4,412 Views)

Telling us that you tried "many ways" isn't very helpful.  Show us the code where you try to extract the data from the file.  Don't upload a PICTURE of the block diagram, upload the actual VI.  A picture of the block diagram is as useful to us as a picture of your engine is to a mechanic.

 

Extracting an array of data should be an easy, if tedious, thing to do.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 7
(4,387 Views)

Vij@y  a écrit :

 

XML file will have a customized data which we required for our project. Hence I cant share that file.

Thanks in Advance.

 

Regards,

Vijay


But you can create a reduced version with similar structure with no sensible information that you can share.

 

Without that all we can say is to look at the examples that ship with LabVIEW or have a look at JKI Easy XML toolkit.

 

Ben64

0 Kudos
Message 3 of 7
(4,387 Views)

An XML File is (to a first approximation) a Text File that "encodes" information about LabVIEW "Variables" (Data carried on wires) such as the Type of the Variable (base type such as I16, U32, Dbl, Boolean, String, Path, etc., Array <Size> of <LabVIEW Type>, Cluster of <List of LabVIEW Types>) and the values associated with these types.  There are at least three LabVIEW XML packages that I know about, and each one encodes the data slightly differently.  Obviously, you need to know and understand the Encoding Scheme to see, for example, if it is consistent with JKI's EasyXML, or with LabVIEW's native XML functions.

 

We may be able to help.  I realize that you have "proprietary" XML data that you cannot share with us, but you can surely find a small (say 50-100 line) XML File, open it in an ordinary Text Editor, and change the Tags and other Elements to make it "Generic" (try naming variables such things as "Var1", "Var2", etc., and use "made up" values such as simple numbers (1, 2, 3 for integers, 1.0, 2.0, 3.0 for Floats) or simple Strings ("String1", "String2", etc.).  Attach such an XML Text File (include the first few lines, which may clue us as to the source of the XML Encoding) and we can (probably) be more helpful.

 

Bob Schor

0 Kudos
Message 4 of 7
(4,379 Views)

Thank you everyone for the reply.

 

Out of many ways I said, I have attached a vi file which I tried using "Unflatten from XML". But it was only throwing back error 1103.

error.JPG

 

 

 

 

 

 

 

 

 

 

As well as I have attached an xml file, which is a simple xml file having some data irrelevant to my work. I believe If I can able read this xml file, then I can read my actual XML file too. 

This forum is not letting me to attach an XML file. So I rename the file extension as "7z". Requesting you people to change the extension and work.

 

 

Regards,

Vijay

Download All
0 Kudos
Message 5 of 7
(4,362 Views)

You can only use Unflatten from XML with files compliant with the LabVIEW XML Schema(LVXMLSchema.xsd) which is use when you create an xml file using flatten to xml.

 

Have a look at the example "Load XML with Parser API.vi", you just have to change the word "TestSetting" to "food" and replace the testsetting cluster by a food cluster than contains the name, price, description and calories elements. Do not validate on load.

 

Ben64

0 Kudos
Message 6 of 7
(4,342 Views)

Suggestion -- next time you want to attach a text file, don't use the extension .7z (which is an extension for a specific compression format).  After failing to uncompress your file, I tried to open it with an ordinary Text editor to see why I was having a problem, and, behold, it's a text file holding XML data!

 

As a LabVIEW Developer looking at the file, I can see that it is probably meant to be an Array called "breakfast menu" of type "food", a cluster of four elements, all strings:  name, price, description, and calories.  If LabVIEW knows this format, it can "look for it" and when it finds it, can load the appropriate LabVIEW Variables from the file.  But somehow you need to tell it what to expect.

 

Ben's suggestion is a good one.  This appears to be related to LabVIEW's native XML support, not so well documented, but there are Examples that ship with LabVIEW that can probably give you a clue (and suggest experiments you can run to see how parsing XML really works).

 

How is the XML file being generated?  Often XML Generation and XML Parsing go hand-in-hand -- a consistent set of rules needs to be followed to convert LabVIEW Variables into and out of an XML string representation.

 

Bob Schor

0 Kudos
Message 7 of 7
(4,334 Views)