Re: PHP5 DOM - DomDocumentFragments empty
| From: | Jason Barnett | Date: | Wed, 02 Mar 2005 20:25:37 +0000 |
| Subject: | Re: PHP5 DOM - DomDocumentFragments empty | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-209848@lists.php.net to get a copy of this message | ||
Here is a modified version of the code that you posted that should
explain it.
<?php
$xmlData = <<<XMLDATA
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<subElement>content</subElement>
</root>
XMLDATA;
$dom = new DomDocument;
$dom->loadXML( $xmlData );
$dom2 = new DomDocument;
$fragment = $dom2->createDocumentFragment();
foreach( $dom->childNodes AS $node ) {
$newNode = $dom2->importNode( $node, true );
/** This is the (undocumented?) way to get the value of a text node */
var_dump($newNode->nodeValue);
$fragment->appendChild( $newNode );
/** Now we see what the value of the $fragment is */
var_dump($fragment);
}
$dom2->appendChild( $fragment );
/** Finally, we echo the XML of the new document */
echo $dom2->saveXML();
?>
--
Teach a man to fish...
NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-general&w=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHP&submitform=Find+search+plugins
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc