LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XML: Deleting a Node with Subnodes – How to do it?

Hello everyone,

I'm working with XML files in LabVIEW and facing the following challenge:

I want to delete a specific node from an XML file. This node itself has several subnodes that should also be deleted when the parent node is removed.

So far, I've managed to delete individual subnodes. However, my problem is that I don't know how to delete a "main node" that still contains child nodes, so that the entire branch is removed from the XML structure.

Is there a specific function in LabVIEW or a recommended approach to remove a node along with all its subnodes? Any help or an example VI would be greatly appreciated!

Thank you in advance for your support!

lxnncrd_0-1765269628921.png

 

 

0 Kudos
Message 1 of 5
(198 Views)

Hi,

 

Just get the "Parent" of the node you want to remove, then call "Remove Child":

 

raphschru_0-1765274193246.png

 

A more complex code is required in case you also want to remove the extra spaces (text nodes) before/after the removed element.

 

Side note: Reference for XPath syntax: https://www.w3schools.com/xml/xpath_syntax.asp

 

Regards,

Raphaël.

Message 2 of 5
(175 Views)

Thank you, I will Try it!

 

0 Kudos
Message 3 of 5
(164 Views)

Just a quick note about XML in LabVIEW:

 

Unless someone did some fixing or optimizing in the last few releases without me hearing about it, the built-in parser can get really slow when you get to large XML files (over 1 megabyte).

 

Before you get too deep into using the built-in XML parsing, if you think there's a remote chance that you will want to work with large files in the future, you might want to change to a 3rd-party parser early on while it's still easy to change.

 

This is the best discussion I have found on this problem, though it's from quite a while ago:

https://forums.ni.com/t5/LabVIEW/Why-does-reading-XML-take-so-long/td-p/2056752

 

It's originally from 2012 but there are updates on the last page from 2022 indicating that it is still an issue.

Message 4 of 5
(123 Views)

FYI, using the XML library in the link, saw an improvement of 340x. (I based this on the number of iterations - 340 - and the fact that with the library mentioned above, completed all the iterations in less time than it took do process one iteration with native LV XML code.)

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 5 of 5
(57 Views)