Page 1 of 1

PHP DOM

Posted: Wed Jan 14, 2009 6:17 am
by mintedjo
I'm trying to replace a table element in a php domdocument object but I keep getting this error
computer wrote:Uncaught exception 'DOMException' with message 'Not Found Error'
on the line of the replaceChild.
Apparently it occurs when you try to replace a node which is NOT a child member of the specified domnode.

I checked that I wasnt initialising the variable twice or anything (and i'm not). I tried cutting out any other dom functions in between so that all i did was initialise the variables and then use them. These didn't work so I tried calling importNode first to make sure the nodes were both part of the same document.

Anyway I can't figure it out. Below is the general gist of what I'm doing so if anybody can see whats wrong let me know plx! :-)

Code: Select all

$xml_document = new DOMDocument("1.0"); // Create a new DOMDocument
$xml_document->loadXML($someXmlString); // This string loads correctly and includes one "Table" element
$dom_table = $xml_document->createElement("Table"); // Create the new Table element
$old_table = $xml_document->getElementsByTagName("Table")->item(0); // Find the old table element (It does find it correctly - I've checked)
$xml_document->replaceChild($dom_table, $old_table); // Replace the old table element with the new one and fail...
EDIT: Just realised the error message has changed - I'll update this in a minute...
EDIT2: Ok I've changed the details that were wrong (and put the line that i corrected in bold) - but i`m still stuck :-)

Re: PHP DOM

Posted: Wed Jan 14, 2009 8:47 am
by mintedjo
Ok I got it to work...
I think the old node which is being replaced has to be a direct descendent of the object calling the function so trying to call the function from the DOMDocument itself didn't work because the table element was nested within another element.