Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>On the save-and-load approach, you could also try <a href="http://www.php.net/manual/en/domdocument.normalizedocument.php" rel="nofollow noreferrer"><code>Document.normalizeDocument</code></a>. This should fix up the document as if it had been save-cycled, without actually really serialising. One thing that should do would be to re-calculate the <a href="http://www.php.net/manual/en/domattr.isid.php" rel="nofollow noreferrer"><code>isID</code></a>-ness of attributes from the document type, which you'd <em>hope</em> would have been set to one of the HTML doctypes (that define <code>id</code> as being an attribute of value type ID) by <code>loadHTML</code>.</p> <p>(There is also <a href="http://www.php.net/manual/en/domelement.setidattribute.php" rel="nofollow noreferrer"><code>Element.setIdAttribute</code></a> which can be used to declare one instance of an <code>Attr</code> to contain an ID, but that's no use to you since you'd have to get hold of it first.)</p> <p>I haven't tested this though and it wouldn't surprise me if PHP didn't implement this DOM Level 3 Core stuff properly. By my interpretation of <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#Attr-isId" rel="nofollow noreferrer">the spec for <code>isId</code></a>, I reckon it should have picked up the <code>id</code> type definition already automatically. (My own DOM implementation certainly does.) But in that case your code would have worked. And I suppose <code>appendXML</code> is a non-standard method after all, so there's nothing to say it has to resolve type definitions like <code>loadXML</code> or <code>loadHTML</code> would.</p> <p>So, maybe a workaround is a better plan. You might use a <a href="http://php.net/manual/en/class.domxpath.php" rel="nofollow noreferrer">DOMXPath</a> to select the element by <code>@id</code> attribute rather than real IDness as such. Of course this will be much slower than <code>getElementById</code>, but hopefully faster than <code>normalizeDocument</code>.</p> <p>Or just lose the XML string-slinging and stick to the DOM methods, if you can; then it's trivial to keep a reference to a created element. (You can use helper functions to create the elements a bit more quickly if you find the DOM methods too wordy for the amount of content you're creating.)</p>
 

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