<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Substitutes XIncludes in a DOMDocument Object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domdocument.validate.html">DOMDocument::validate</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.domdocumentfragment.html">DOMDocumentFragment</a></div> <div class="up"><a href="class.domdocument.html">DOMDocument</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="domdocument.xinclude" class="refentry"> <div class="refnamediv"> <h1 class="refname">DOMDocument::xinclude</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">DOMDocument::xinclude</span> — <span class="dc-title"> Substitutes XIncludes in a DOMDocument Object </span></p> </div> <div class="refsect1 description" id="refsect1-domdocument.xinclude-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><strong>DOMDocument::xinclude</strong></span> ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code></span> ] )</div> <p class="para rdfs-comment"> This method substitutes <a href="http://www.w3.org/TR/xinclude/" class="link external">» XIncludes</a> in a DOMDocument object. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Due to libxml2 automatically resolving entities, this method will produce unexpected results if the included XML file have an attached DTD. </p> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-domdocument.xinclude-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">options</code></em></span> <dd> <p class="para"> <a href="libxml.constants.html" class="link">libxml parameters</a>. Available since PHP 5.1.0 and Libxml 2.6.7. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-domdocument.xinclude-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the number of XIncludes in the document, -1 if some processing failed, or <strong><code>FALSE</code></strong> if there were no substitutions. </p> </div> <div class="refsect1 examples" id="refsect1-domdocument.xinclude-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5419"> <p><strong>Example #1 DOMDocument::xinclude() example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br />$xml </span><span style="color: #007700">= <<<EOD<br /></span><span style="color: #DD0000"><?xml version="1.0" ?><br /><chapter xmlns:xi="http://www.w3.org/2001/XInclude"><br /> <title>Books of the other guy..</title><br /> <para><br /> <xi:include href="book.xml"><br /> <xi:fallback><br /> <error>xinclude: book.xml not found</error><br /> </xi:fallback><br /> </xi:include><br /> </para><br /></chapter><br /></span><span style="color: #007700">EOD;<br /><br /></span><span style="color: #0000BB">$dom </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// let's have a nice output<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-></span><span style="color: #0000BB">preserveWhiteSpace </span><span style="color: #007700">= </span><span style="color: #0000BB">false</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-></span><span style="color: #0000BB">formatOutput </span><span style="color: #007700">= </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// load the XML string defined above<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-></span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #0000BB">$xml</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// substitute xincludes<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-></span><span style="color: #0000BB">xinclude</span><span style="color: #007700">();<br /><br />echo </span><span style="color: #0000BB">$dom</span><span style="color: #007700">-></span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> <?xml version="1.0"?> <chapter xmlns:xi="http://www.w3.org/2001/XInclude"> <title>Books of the other guy..</title> <para> <row xml:base="/home/didou/book.xml"> <entry>The Grapes of Wrath</entry> <entry>John Steinbeck</entry> <entry>en</entry> <entry>0140186409</entry> </row> <row xml:base="/home/didou/book.xml"> <entry>The Pearl</entry> <entry>John Steinbeck</entry> <entry>en</entry> <entry>014017737X</entry> </row> <row xml:base="/home/didou/book.xml"> <entry>Samarcande</entry> <entry>Amine Maalouf</entry> <entry>fr</entry> <entry>2253051209</entry> </row> </para> </chapter> </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domdocument.validate.html">DOMDocument::validate</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.domdocumentfragment.html">DOMDocumentFragment</a></div> <div class="up"><a href="class.domdocument.html">DOMDocument</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>