note 46573 added to function.dom-domdocument-importnode
| From: | t dot taelle at kytelis dot de | Date: | Fri, 15 Oct 2004 18:59:31 +0000 |
| Subject: | note 46573 added to function.dom-domdocument-importnode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78602@lists.php.net to get a copy of this message | ||
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();
?>
----
Manual Page -- http://www.php.net/manual/en/function.dom-domdocument-importnode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46573
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46573&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46573&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46573&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46573&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46573&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46573&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46573&report=yes
Search -- http://master.php.net/manage/user-notes.php