# Replace XmlTree child node

**URL:** https://discourse.libcinder.org/t/replace-xmltree-child-node/255
**Category:** Using Cinder
**Created:** [September 8, 2016, 9:55am UTC](https://discourse.libcinder.org/t/replace-xmltree-child-node/255 "2016-09-08T09:55:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![daniel](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/daniel/32/50_2.png) [@daniel](https://discourse.libcinder.org/u/daniel)
#### Post date: [September 8, 2016, 9:55am UTC](https://discourse.libcinder.org/t/replace-xmltree-child-node/255/1 "2016-09-08T09:55:02Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![gabor\_papp](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gabor_papp/32/769_2.png) [@gabor\_papp](https://discourse.libcinder.org/u/gabor_papp)
#### Post date: [September 8, 2016, 10:04am UTC](https://discourse.libcinder.org/t/replace-xmltree-child-node/255/2 "2016-09-08T10:04:56Z")

</div>

Hi,

This thread might help from the [old forum](https://forum.libcinder.org/topic/remove-replace-xml-tag).

-Gabor

---

<div class="post-metadata">

### Author: ![daniel](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/daniel/32/50_2.png) [@daniel](https://discourse.libcinder.org/u/daniel)
#### Post date: [September 8, 2016, 10:13am UTC](https://discourse.libcinder.org/t/replace-xmltree-child-node/255/3 "2016-09-08T10:13:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)
#### Post date: [September 8, 2016, 11:19am UTC](https://discourse.libcinder.org/t/replace-xmltree-child-node/255/4 "2016-09-08T11:19:53Z")

</div>

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

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

---

<div class="post-metadata">

### Author: ![daniel](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/daniel/32/50_2.png) [@daniel](https://discourse.libcinder.org/u/daniel)
#### Post date: [September 8, 2016, 12:01pm UTC](https://discourse.libcinder.org/t/replace-xmltree-child-node/255/5 "2016-09-08T12:01:39Z")

</div>

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