flashdomm Posted June 17, 2010 Share Posted June 17, 2010 Hi Guys, I am pulling my hair out by this point, hope someone can help... I am trying to update a single xml text node via xml dom, but can't get it no matter what... Here's the php I have: $xml = new DOMDocument('1.0'); $xml->load('system.xml'); $element = $xml->getElementsByTagName('status'); $newElement = $xml->createTextNode('published'); $element->replaceChild($newElement, $element); $xml->save('ooo.xml'); system.xml sample: <?xml version="1.0" encoding="utf-8"?> <images> <image> <file>stairs</file> <dir>../images/slideshow/</dir> <status>published</status> </image> <image> <file>flower</file> <dir>../images/slideshow/</dir> <status>published</status> </image> I am pobably not telling php of the text nodes parents, but I find this dom xml really confusing... I will also using simpleXML in the document so mabye u can show me how to convert simpleXML to dom. If someone could give me code that works with some simple comments I would be forever grateful. Link to comment https://forums.phpfreaks.com/topic/205000-xml-dom-replace-text-node-pls-help/ Share on other sites More sharing options...
flashdomm Posted June 18, 2010 Author Share Posted June 18, 2010 Someone suggested this but it still doesn't work, anyone can see the problem?? $nodes = $dom->getElementsByTagName('status'); $textNode = $dom->createTextNode('pub'); foreach($nodes as $status) { $textNode2 = $dom->importNode($textNode, true); $status->replaceChild($textNode2, $oldNode); } Not sure what $oldNode supposed to be Link to comment https://forums.phpfreaks.com/topic/205000-xml-dom-replace-text-node-pls-help/#findComment-1073968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.