Note that there are some explanatory texts on larger screens.

plurals
  1. PODOMNode reference doesn't work anymore after appending it to another element twice
    primarykey
    data
    text
    <p>I'm using the a wrapper around the PHP5-class DOMDocument to generate my HTML. This makes it easy to modify the HTML by using the DOM.</p> <p>An example is creating element #1 and adding it to the element #2 and still be able to modify element #1 directly.</p> <p>A problem arises however with the following:</p> <ul> <li>Element #1 is added to element #2</li> <li>Element #2 is added to element #3</li> <li>Element #1 is modified but no changes are visible in the DOM of element #3 (which contains #1 and #2)</li> </ul> <p>A simplified sample code:</p> <pre><code>&lt;?php $doc1 = new DOMDocument(); $el1 = $doc1-&gt;createElement('h1', 'Hello'); $doc1-&gt;appendChild($el1); $doc2 = new DOMDocument(); $el2 = $doc2-&gt;createElement('h2', 'World'); $doc2-&gt;appendChild($el2); $doc3 = new DOMDocument(); $el3 = $doc3-&gt;createElement('h3', 'Today'); $doc3-&gt;appendChild($el3); // Import el1 into el2 $el1 = $doc2-&gt;importNode($el1, true); $el2-&gt;appendChild( $el1 ); $doc1 = $doc2; // Import el2 into el3 $el2 = $doc3-&gt;importNode($el2, true); $el3-&gt;appendChild($el2); $doc2 = $doc3; // Modify el1 $el1-&gt;nodeValue = "Boo"; // This doesn't work? //$el2-&gt;nodeValue = "Boo"; // Changing element2 or 3 works... // Display result echo $doc3-&gt;saveHTML(); ?&gt;` </code></pre> <p>Modifying $el2 is still possible because it is deep-copied and added to $el3's DOM. $el1 however still points to $doc2/$el2's DOM and any changes are not reflected in $el3's DOM.</p> <p>Are there any generic ways to to directly point $el1 to the right node in $el3's DOM?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload