cvs: phpdoc /en/reference/dom/domdocument importnode.xml

From: Date: Tue, 28 Oct 2008 08:55:58 +0000
Subject: cvs: phpdoc /en/reference/dom/domdocument importnode.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2314@lists.php.net to get a copy of this message
bjori Tue Oct 28 08:55:58 2008 UTC Modified files: /phpdoc/en/reference/dom/domdocument importnode.xml Log: Add example http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/dom/domdocument/importnode.xml?r1=1.4&r2=1.5&diff_format=u Index: phpdoc/en/reference/dom/domdocument/importnode.xml diff -u phpdoc/en/reference/dom/domdocument/importnode.xml:1.4 phpdoc/en/reference/dom/domdocument/importnode.xml:1.5 --- phpdoc/en/reference/dom/domdocument/importnode.xml:1.4 Fri Dec 28 17:47:05 2007 +++ phpdoc/en/reference/dom/domdocument/importnode.xml Tue Oct 28 08:55:57 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry xml:id="domdocument.importnode" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>DOMDocument::importNode</refname> @@ -53,6 +53,69 @@ <classname>DOMException</classname> is thrown if node cannot be imported. </para> </refsect1> + <refsect1 role="examples"> + &reftitle.examples; + <para> + <example> + <title><function>DOMDocument::importNode</function> example</title> + <para> + Copying nodes between documents. + </para> + <programlisting role="php"> +<![CDATA[ +<?php + +$orgdoc = new DOMDocument; +$orgdoc->loadXML("<root><element><child>text in child</child></element></root>"); + +// The node we want to import to a new document +$node = $orgdoc->getElementsByTagName("element")->item(0); + + +// Create a new document +$newdoc = new DOMDocument; +$newdoc->formatOutput = true; + +// Add some markup +$newdoc->loadXML("<root><someelement>text in some element</someelement></root>"); + +echo "The 'new document' before copying nodes into it:\n"; +echo $newdoc->saveXML(); + +// Import the node, and all its children, to the document +$node = $newdoc->importNode($node, true); +// And then append it to the "<root>" node +$newdoc->documentElement->appendChild($node); + +echo "\nThe 'new document' after copying the nodes into it:\n"; +echo $newdoc->saveXML(); +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +The 'new document' before copying nodes into it: +<?xml version="1.0"?> +<root> + <someelement>text in some element</someelement> +</root> + +The 'new document' after copying the nodes into it: +<?xml version="1.0"?> +<root> + <someelement>text in some element</someelement> + <element> + <child>text in child</child> + </element> +</root> +]]> + </screen> + </example> + </para> + </refsect1> + + </refentry> <!-- Keep this comment at the end of the file

« previous php.doc.cvs (#2314) next »