Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(this is not a real answer, but a consolidation of comments and answers posted here and related questions)</p> <hr> <p>This new version of the question's <code>DOMXpath_reuser</code> function contains the @ThomasWeinert suggestion (for avoid DOM changes by external re-<code>load</code>) and an option <code>$enforceRefresh</code> to workaround the problem of instability (as related question shows the programmer must detect <em>when</em>). </p> <pre class="lang-php prettyprint-override"><code> function DOMXpath_reuser_v2($file, $enforceRefresh=0) { //changed here static $doc=NULL; static $docName=''; static $xp=NULL; if (!$doc) $doc = new DOMDocument(); if ( $file!=$docName || ($xp &amp;&amp; $doc !== $xp-&gt;document) ) { // changed here $doc-&gt;load($file); $xp = NULL; } elseif ($enforceRefresh==2) { // add this new refresh mode $doc-&gt;loadXML($doc-&gt;saveXML()); $xp = NULL; } if (!$xp || $enforceRefresh==1) //changed here $xp = new DOMXpath($doc); return $xp; } </code></pre> <h2>When must to use $enforceRefresh=1 ?</h2> <p>... perhaps an open problem, only little tips and clues...</p> <ul> <li>when DOM submited to setAttribute, removeChild, replaceChild, etc.</li> <li>...? more cases?</li> </ul> <h2>When must to use $enforceRefresh=2 ?</h2> <p>... perhaps an open problem, only little tips and clues...</p> <ul> <li>when DOM was subject to indexes inconsistences, etc. See <a href="https://stackoverflow.com/q/20114285/287948">this question/solution</a>.</li> <li>...? more cases?</li> </ul>
    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. VO
      singulars
      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