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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.