Jump to content

XML Dom replace text node pls help!!!


flashdomm

Recommended Posts

Hi Guys,

 

I am pulling my hair out by this point, hope someone can help...  :rtfm:

 

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

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  :shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.