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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.