LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Append New Element to XML File

Novice to labview and XML here, and I don't seem to understand the flow well enough to Open an XML file, remove some data, replace with some new data and save. I've gotten as far as opening, parsing and deleting, but appending new data eludes me. 

 

I created the VI below as a test. I can delete "ConfigTable" in Index 1, but I dont understand what the flow should be to replace it with new data. I'd think I could append a new child just after removing the old child, but to add a new XML string in requires a reference in, and I don't know where that reference should come from? 

 

Is there a way I can spell out the exact path that I want to add data to (I.E. cfg_root/cfg_records/ConfigTable[1]) and then starting adding new children at that point? Thank you. 

 

Download All
0 Kudos
Message 1 of 4
(4,730 Views)

If you look at the Generate XML string with parser-Example, there's a new helper-vi which does exactly what you want. You'll need 4 nodes.
Create XML Tag.png

/Y

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 2 of 4
(4,686 Views)

Adding a 6th array element in your case would manually be something like this:
Add XML Node.png

/Y

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

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

Thank you both so much. In the meantime I had worked out exactly what was suggested, using a modified version of the example VI to add attributes instead of elements. 

 

The one issue I had was actually with removing the existing element at #5, which I originally thought I had solved. I was having a problem with removing the elements from ConfigTable 5 without losing all the other XML. I came up with the following, and it seems to work, but am I committing any sins? I did notice that it adds an extra newline before "</cfg_record>" but that doesn't seem to matter. As I'm sure you can tell I'm very unclear on when the "Close" function should be used. 

Download All
0 Kudos
Message 4 of 4
(4,677 Views)