note 46573 deleted from function.dom-domdocument-importnode by tularis
| From: | tularis@php.net | Date: | Fri, 15 Oct 2004 19:46:44 +0000 |
| Subject: | note 46573 deleted from function.dom-domdocument-importnode by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78606@lists.php.net to get a copy of this message | ||
Note Submitter: t dot taelle at kytelis dot de
----
Thema con variazione
inspired by (jon at codessence dot net):
<?php
// your xml
$doc = new DOMDocument;
$doc->loadXML('<?xml version="1.0" encoding="UTF-8"?>
<page>
<paragraph>blah blah blah blah</paragraph>
</page>');
// your paragraph in well formed xhtml with links
// and is embedded in a string of xml like so...
$import_dom = new DOMDocument;
$import_dom->loadXML('<?xml version="1.0" encoding="UTF-8"?>
<paragraph>Hello <a href="http://www.google.com">World</a>!</paragraph>');
$nodeToCopy = $import_dom->getElementsByTagName('paragraph')->item (0);
// use importNode with 2nd arg TRUE to import all descendants of a node
$paragraph = $doc->importNode($nodeToCopy, true);
// append the new node to the root node (documentElement)
$paragraph = $doc->documentElement->appendChild($paragraph);
// save your new XML
echo $doc->saveXML();
?>