harshpandya Posted September 12, 2008 Share Posted September 12, 2008 Here is my XML doc::<root><device> <name>My name</name></device></root>Here is my code : I want to remove name node from the XML and create new one with different node value$root = $xmlDoc->documentElement;$child2 = $root->getElementsByTagName("name")->item(0);$root->removeChild($child2);why this wont work?Thanks, Link to comment Share on other sites More sharing options...
justsomeguy Posted September 12, 2008 Share Posted September 12, 2008 The name node isn't a child of root, it's a child of a device node. The device node is the child of root. Link to comment Share on other sites More sharing options...
Jesdisciple Posted September 12, 2008 Share Posted September 12, 2008 Try removing it from its parent element instead: $root = $xmlDoc->documentElement;$child2 = $root->getElementsByTagName("name")->item(0);$child2->parent->removeChild($child2); Also, you might prefer replaceChild. Link to comment Share on other sites More sharing options...
harshpandya Posted September 12, 2008 Author Share Posted September 12, 2008 Thanks Guys for help ,,J/D your code has syntax problem i fixed it $child2->parent->removeChild($child2); instead of this, i used the bottom one $child2->parentNode->removeChild($child2);Thanks, Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.