XML dom replace childs



Here is xml file



<stuff>
<foo>
<bar></bar>
<value/>
<pub></pub>
</foo>
<foo>
<bar></bar>
<pub></pub>
</foo>
<foo>
<bar></bar>
<pub></pub>
</foo>
</stuff>


Then i trying to use code



$new=$dom>createTextNode('newnodeName');

$elements = $dom->getElementsByTagName('foo');
foreach($elements as $node){
foreach($node->childNodes as $child) {
$child->parentNode->replaceChild($new, $child);
}
}



  1. Why this code not replace each $child by $new value

  2. REturn output in string format not in XML?

  3. How to change root TagName "stuff" to "team" ?


No comments:

Post a Comment