downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.simplexml-import-dom.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.simplexml.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'function.simplexml-import-dom.php',
   
1 => 'simplexml_import_dom',
  ),
 
'up' =>
  array (
   
0 => 'ref.simplexml.php',
   
1 => 'SimpleXML Functions',
  ),
 
'prev' =>
  array (
   
0 => 'ref.simplexml.php',
   
1 => 'SimpleXML Functions',
  ),
 
'next' =>
  array (
   
0 => 'function.simplexml-load-file.php',
   
1 => 'simplexml_load_file',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.simplexml-import-dom" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">simplexml_import_dom</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">simplexml_import_dom</span> &mdash; <span class="dc-title">Get a <i>SimpleXMLElement</i> object from a DOM node.</span></p>

 </div>
 <a name="function.simplexml-import-dom.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="class.simplexmlelement.php" class="type SimpleXMLElement">SimpleXMLElement</a></span> <span class="methodname"><b>simplexml_import_dom</b></span>
    ( <span class="methodparam"><span class="type"><a href="class.domnode.php" class="type DOMNode">DOMNode</a></span> <tt class="parameter">$node</tt></span>
   [, <span class="methodparam"><span class="type">string</span> <tt class="parameter">$class_name</tt><span class="initializer"> = &quot;SimpleXMLElement&quot;</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   This function takes a node of a <a href="book.dom.php" class="link">DOM</a>
   document and makes it into a SimpleXML node. This new object can
   then be used as a native SimpleXML element.
  </p>
 </div>


 <a name="function.simplexml-import-dom.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">node</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       A <a href="book.dom.php" class="link">DOM</a> Element node
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">class_name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       You may use this optional parameter so that
       <b>simplexml_import_dom()</b> will return an object of
       the specified class. That class should extend the
       <a href="class.simplexmlelement.php" class="type SimpleXMLElement">SimpleXMLElement</a> class.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.simplexml-import-dom.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns a <a href="class.simplexmlelement.php" class="type SimpleXMLElement">SimpleXMLElement</a> or <b><tt class="constant">FALSE</tt></b> on failure.
  </p>
 </div>


 <a name="function.simplexml-import-dom.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Importing DOM</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dom&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$dom</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;books&gt;&lt;book&gt;&lt;title&gt;blah&lt;/title&gt;&lt;/book&gt;&lt;/books&gt;'</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$dom</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error&nbsp;while&nbsp;parsing&nbsp;the&nbsp;document'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$s&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">simplexml_import_dom</span><span style="color: #007700">(</span><span style="color: #0000BB">$dom</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$s</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">book</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]-&gt;</span><span style="color: #0000BB">title</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;blah<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>
  </p>
 </div>


 <a name="function.simplexml-import-dom.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.dom-import-simplexml.php" class="function" rel="rdfs-seeAlso">dom_import_simplexml()</a> - Gets a DOMElement object from a
   SimpleXMLElement object</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites