<!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>Load XML from a file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domdocument.importnode.html">DOMDocument::importNode</a></div> <div class="next" style="text-align: right; float: right;"><a href="domdocument.loadhtml.html">DOMDocument::loadHTML</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.load" class="refentry"> <div class="refnamediv"> <h1 class="refname">DOMDocument::load</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">DOMDocument::load</span> — <span class="dc-title"> Load XML from a file </span></p> </div> <div class="refsect1 description" id="refsect1-domdocument.load-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>DOMDocument::load</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span> ] )</div> <p class="para rdfs-comment"> Loads an XML document from a file. </p> <div class="warning"><strong class="warning">Warning</strong> <p class="simpara"> Unix style paths with forward slashes can cause significant performance degradation on Windows systems; be sure to call <span class="function"><a href="function.realpath.html" class="function">realpath()</a></span> in such a case. </p> </div> </div> <div class="refsect1 parameters" id="refsect1-domdocument.load-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> The path to the XML document. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">options</code></em></span> <dd> <p class="para"> <a href="language.operators.bitwise.html" class="link">Bitwise <em>OR</em></a> of the <a href="libxml.constants.html" class="link">libxml option constants</a>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-domdocument.load-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. If called statically, returns a <a href="class.domdocument.html" class="classname">DOMDocument</a> or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 errors" id="refsect1-domdocument.load-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> If an empty string is passed as the <em><code class="parameter">filename</code></em> or an empty file is named, a warning will be generated. This warning is not generated by libxml and cannot be handled using libxml's error handling functions. </p> <p class="para">This method <em class="emphasis">may</em> be called statically, but will issue an <strong><code>E_STRICT</code></strong> error.</p> </div> <div class="refsect1 examples" id="refsect1-domdocument.load-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5406"> <p><strong>Example #1 Creating a Document</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$doc </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-></span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #DD0000">'book.xml'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$doc</span><span style="color: #007700">-></span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-domdocument.load-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="domdocument.loadxml.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::loadXML()</a> - Load XML from a string</span></li> <li class="member"> <span class="methodname"><a href="domdocument.save.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::save()</a> - Dumps the internal XML tree back into a file</span></li> <li class="member"> <span class="methodname"><a href="domdocument.savexml.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveXML()</a> - Dumps the internal XML tree back into a string</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domdocument.importnode.html">DOMDocument::importNode</a></div> <div class="next" style="text-align: right; float: right;"><a href="domdocument.loadhtml.html">DOMDocument::loadHTML</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>