I need to load some arbitrary HTML into an existing DOMDocument
tree. Previous answers suggest using DOMDocumentFragment
and its appendXML
method to handle this.
As @Owlvark indicates in the comments, xml is not html and therefore this is not a good solution.
The main issue that I had with it was that entities like &ndash
were causing errors because the appendXML
method expects well formed XML.
We could define the entities, but this doesn't take care of the problem that not all html is valid xml.
What is a good solution for importing HTML into a DOMDocument
tree?
libxml_use_internal_errors()
and ignore it... Also, you're loading the document usingDomDocument::loadHtml()
right? – UndershootloadHtml
, I am not. I am using theDOMDocumentFragment::appendXML
– Metcalf