<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.domdocument.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'domdocument.importnode.php',
    1 => 'DOMDocument::importNode',
    2 => 'Import node into current document',
  ),
  'up' => 
  array (
    0 => 'class.domdocument.php',
    1 => 'DOMDocument',
  ),
  'prev' => 
  array (
    0 => 'domdocument.getelementsbytagnamens.php',
    1 => 'DOMDocument::getElementsByTagNameNS',
  ),
  'next' => 
  array (
    0 => 'domdocument.load.php',
    1 => 'DOMDocument::load',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dom/domdocument/importnode.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="domdocument.importnode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMDocument::importNode</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DOMDocument::importNode</span> &mdash; <span class="dc-title">Import node into current document</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domdocument.importnode-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DOMDocument::importNode</strong></span>(<span class="methodparam"><span class="type"><a href="class.domnode.php" class="type DOMNode">DOMNode</a></span> <code class="parameter">$node</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$deep</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><span class="type"><a href="class.domnode.php" class="type DOMNode">DOMNode</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   This function returns a copy of the node to import and associates it with 
   the current document.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domdocument.importnode-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">node</code></dt>
     <dd>
      <p class="para">
       The node to import.
      </p>
     </dd>
    
    
     <dt><code class="parameter">deep</code></dt>
     <dd>
      <p class="para">
       If set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, this method will recursively import the subtree under
       the <code class="parameter">node</code>.
      </p>
      <blockquote class="note"><p><strong class="note">Nota</strong>: 
       <p class="para">
        To copy the nodes attributes <code class="parameter">deep</code> needs to be set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domdocument.importnode-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   The copied node or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, if it cannot be copied.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-domdocument.importnode-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   <span class="classname"><a href="class.domexception.php" class="classname">DOMException</a></span> is thrown if node cannot be imported.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-domdocument.importnode-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>DOMDocument::importNode()</strong></span> example</strong></p>
    <div class="example-contents"><p>
      Copying nodes between documents.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$orgdoc </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$orgdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;root&gt;&lt;element&gt;&lt;child&gt;text in child&lt;/child&gt;&lt;/element&gt;&lt;/root&gt;"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// The node we want to import to a new document<br /></span><span style="color: #0000BB">$node </span><span style="color: #007700">= </span><span style="color: #0000BB">$orgdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getElementsByTagName</span><span style="color: #007700">(</span><span style="color: #DD0000">"element"</span><span style="color: #007700">)-&gt;</span><span style="color: #0000BB">item</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">// Create a new document<br /></span><span style="color: #0000BB">$newdoc </span><span style="color: #007700">= new </span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newdoc</span><span style="color: #007700">-&gt;</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">// Add some markup<br /></span><span style="color: #0000BB">$newdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">"&lt;root&gt;&lt;someelement&gt;text in some element&lt;/someelement&gt;&lt;/root&gt;"</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"The 'new document' before copying nodes into it:\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$newdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Import the node, and all its children, to the document<br /></span><span style="color: #0000BB">$node </span><span style="color: #007700">= </span><span style="color: #0000BB">$newdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">importNode</span><span style="color: #007700">(</span><span style="color: #0000BB">$node</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">// And then append it to the "&lt;root&gt;" node<br /></span><span style="color: #0000BB">$newdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">documentElement</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">appendChild</span><span style="color: #007700">(</span><span style="color: #0000BB">$node</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"\nThe 'new document' after copying the nodes into it:\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$newdoc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">The &#039;new document&#039; before copying nodes into it:
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;root&gt;
  &lt;someelement&gt;text in some element&lt;/someelement&gt;
&lt;/root&gt;

The &#039;new document&#039; after copying the nodes into it:
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;root&gt;
  &lt;someelement&gt;text in some element&lt;/someelement&gt;
  &lt;element&gt;
    &lt;child&gt;text in child&lt;/child&gt;
  &lt;/element&gt;
&lt;/root&gt;</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 

</div><?php manual_footer($setup); ?>