Replace XmlTree child node

Hello,

I am trying to figure out how to replace a node in an XmlTree object. Something like:

for ( XmlTree node : myConfig ) {
  if ( node->getTag() == "reference" ) {
    node = myOtherNode;
  }
}

So that the old node is deleted and myOtherNode is injected at exactly the same position.

Any ideas?

Hi,

This thread might help from the old forum.

-Gabor

1 Like

Perfect, thank you very much! I somehow missed that thread.

You’re copying into node. Try iterating with a reference:

for ( XmlTree& node : myConfig ) 
{ //         ^ This cheeky fellow here.
  if ( node->getTag() == "reference" ) {
    node = myOtherNode;
  }
}
1 Like

haha. Just came back to report my major facepalm. Sorry for the inconvenience :slight_smile: