html5-dom-document-php
html5-dom-document-php copied to clipboard
Feature request: `HTML5DOMDocumentFragment` with `appendHTML()`
Since XML is not HTML, using native DOMDocumentFragment
and its appendXML()
method is risky and prone to all the very same issues this library is trying to address.
There are already two methods to help you with this. Please take a look at HTML5DOMDocument::insertHTML()
and HTML5DOMDocument::insertHTMLMulti()
. There is an example at https://github.com/ivopetkov/html5-dom-document-php (in the README section).
I am implementing a contract that requires me to return a DOMDocumentFragment
.
Would you provide some example code so I can better understand the problem you're trying to solve and the API you're requesting?
I must return a DOMDocumentFragment
, because that is what a contract enforced by a 3rd-party library requires of me. I must also be able to assemble the contents of the resulting DOMDocumentFragment
from pieces, which can be:
-
DOMNode
s, including otherDOMDocumentFragment
s, - strings of raw HTML
YES, I can do this:
- for each
$piece
- if
$piece
is aDOMNode
, just append it to the fragment - else
- create a temporary HTML5DOMDocument
- load a HTML skeleton containing
<div id="processing-container">$piece</div>
into the document - iterate over the children of the processing container, clone them, and append them to the
DOMDocumentFragment
- if
But that is a huge amount of work for what should be much easier to do, and with the requested feature, it would be. If the purpose of this library is to make HTML manipulation easy, then this feature is missing.
Currently, I do not have plans to add fragments support. Maybe someday. Feel free to contribute such code to the library.