From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to XML within loop

I am able to write datas to XML file. But when I am writing inside loop then for second loop it is generating issue and giving error. attached VI which will update for single run successfully. Let me know where is issue

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 1 of 9
(3,646 Views)

This VI works, but in single run and if placed in a loop, so i can't reproduce your issue. Do you manage to close the XML ref in the loop?

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 9
(3,626 Views)

Ok take this VI which I wrote for writing in loop.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 3 of 9
(3,615 Views)

If you unravel the loop you'll notice it's the 2nd Testdata that's causing the error.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 9
(3,607 Views)

If you unwrap the loop you'll notice it's the 2nd Testdata that's causing the error.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 9
(3,607 Views)

I guess where tag is boxno where issue is coming. Let me know how to resolve it

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 6 of 9
(3,603 Views)

@Ranjeet_Singh wrote:

I guess where tag is boxno where issue is coming. Let me know how to resolve it


The problem is your XML tree structure, you must have a single root element. Create a TestSession element before the for loop and the last thing to do in this loop is to append the TestData node to this element. After the loop you append the TestSession element to the document.

 

Ben64

 

XML Loop.png

0 Kudos
Message 7 of 9
(3,536 Views)

@ben64 wrote:


The problem is your XML tree structure, you must have a single root element. Create a TestSession element before the for loop and the last thing to do in this loop is to append the TestData node to this element. After the loop you append the TestSession element to the document.

 

Ben64

 

 


Note that the TestSession node can be appended to the document immediatly after its creation, which is probably better. Then you just close its reference after the loop.

 

Ben64

0 Kudos
Message 8 of 9
(3,500 Views)

XML is an interesting format -- it is "human-readable", seems to "map" reasonably well with LabVIEW data types (various representations of numbers, booleans, strings, paths, arrays, clusters), and there are several (at least 4, I think) implementations of it available for LabVIEW.

 

What's also interesting is that (possibly because of its "open" nature) there is no set way that XML is generated and parsed, and the resulting file formats are often not compatible with each other.  This need not be an issue if you are doing the reading and writing, but can make it a little less "portable".

 

Another interesting thing that I've noticed is that the "model" of how (several) XML systems seem to work is that the file is open, a single Write of "Everything" is done, and the file is closed, with Reading/parsing largely the inverse of this.  In particular, the notion of opening a file and "streaming" data in XML format as it is being generated does not seem to "fit" the usual model.

 

Fortunately, with at least two XML packages (EasyXML from JKI Software, and NI-GXML, from the LabVIEW Tools Network), it is possible to "extend" this model and to allow for such streaming.  In addition, both packages allow a very "intuitive" way to write and read/parse XML in flexible ways.  I'm less familiar with the version of XML that ships with LabVIEW, and haven't looked carefully at LabXML.

 

Bob Schor

0 Kudos
Message 9 of 9
(3,486 Views)