Re: DOM XML difference between PHP versions 4.2.1 and 4.3.3
| From: | Tom Rogers | Date: | Fri, 24 Oct 2003 16:36:34 +0000 |
| Subject: | Re: DOM XML difference between PHP versions 4.2.1 and 4.3.3 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167467@lists.php.net to get a copy of this message | ||
Hi,
Friday, October 24, 2003, 9:37:07 PM, you wrote:
S> Hello
S> I wonder if anyone can help me with this problem or suggest an alternative
S> strategy.
S> I have two PHP boxes, one windows box running PHP version 4.2.1 and DOM XML
S> version 2.4.9, and the other one a FreeBSD box running PHP version 4.3.3 and
S> DOM XML version 2.5.11.
S> What I need to do is to join two XML documents together. The code below
S> runs fine on the 4.2.1 box but fails on the 4.3.3 box.
S> //$pagenodes_doc_xml and $menu_xml have been previously populated with
S> valid XML document objects
S> // get page nodes root element
S> $pagenodes_xml = $pagenodes_doc_xml->document_element();
S> //locate portalroot in menu xml
S> $ctx = xpath_new_context($menu_xml);
S> $nodes = xpath_eval($ctx, "//node[@type='portalroot']");
S> $portalroot = $nodes->nodeset[0];
S> //append pages nodes at portalroot location
S> $new_xml = $portalroot->append_child($pagenodes_xml);
S> The error is "Warning: append_child(): Can't append node, which is in a
S> different document than the parent node".
S> Simon
I think you have to use clone node
$pagenodes_xml = $pagenodes_doc_xml->document_element();
$newnode = $pagenodes_xml->clone_node(1); //don't remember why the 1 :)
$ctx = xpath_new_context($menu_xml);
$nodes = xpath_eval($ctx, "//node[@type='portalroot']");
$portalroot = $nodes->nodeset[0];
$new_xml = $portalroot->append_child($newnode);
--
regards,
Tom