I have a problem. I want to load an HTML fragment with a namespace with DOMDocument.
<div class="something-first">
<div class="something-child something-good another something-great">
<my:text value="huhu">
</div>
</div>
But I can't figure out how to save namespaces. I tried loading it with loadHTML(), but HTML does not have namespaces and therefore they are separated.
I tried to download it using loadXML(), but this will not work, as the reason is <my:text value="huhu">not XML compliant.
I need a method loadHTML()that does not share namespaces or a method loadXML()that does not check markup. So, a combination of these two methods.
My code is:
$html = '<div class="something-first">
<div class="something-child something-good another something-great">
<my:text value="huhu">
</div>
</div>';
libxml_use_internal_errors(true);
$domDoc = new DOMDocument();
$domDoc->formatOutput = false;
$domDoc->resolveExternals = false;
$domDoc->substituteEntities = false;
$domDoc->strictErrorChecking = false;
$domDoc->validateOnParse = false;
$domDoc->loadHTML($html);
$xpath = new DOMXPath($domDoc);
$xpath->registerNamespace ( 'my', 'http://www.example.com/' );
$nodes = $xpath->query('//my:*');
var_dump($nodes);
Is there any way to achieve what I want? I would be very happy for any advice.
EDIT. libxml2, HTML: https://bugzilla.gnome.org/show_bug.cgi?id=711670