Re: DOM appendChild question
| From: | Christian Stocker | Date: | Thu, 26 Feb 2004 08:03:11 +0000 |
| Subject: | Re: DOM appendChild question | ||
| References: | 1 | Groups: | php.xml.dev |
| Request: | Send a blank email to php-xml-dev+get-326@lists.php.net to get a copy of this message | ||
On 2/25/04 8:16 PM, Dan Phiffer wrote:
Sorry if this is the wrong forum for this, but should this work?No. The Exception is there for a reason ;)
$doc = new DomDocument(); $doc->loadXML('<html><body></body></html>'); $hello = new DomDocument(); $hello->loadXML('<p>Hello world!</p>'); $xp = new DomXPath($doc); $body = $xp->query('/html/body')->item(0); $body->appendChild($hello->firstChild); // <-- Exception thrown here echo $doc->saveHTML(); Here's the error message I'm getting: Fatal error: Uncaught exception 'domexception' with message 'Wrong Document Error' in ... Stack trace: #0 {main} thrown in ... on line 18Use $doc->importNode($hello->firstChild); before you do the appendChild. See also http://www.w3.org/TR/2004/PR-DOM-Level-3-Core-20040205/core.html#Core-Document-importNode chregu
I'm running PHP 5 beta 4 on Apache 1.3.29. Thanks! -Dan-- christian stocker | Bitflux GmbH | schoeneggstrasse 5 | ch-8004 zurich phone +41 1 240 56 70 | mobile +41 76 561 88 60 | fax +41 1 240 56 71 http://www.bitflux.ch | chregu@bitflux.ch | gnupg-keyid 0x5CE1DECB