An image tag, after being handled by the DOM parser, is internally treated as:
<img src="test">
Notice that it is not self-closing (that doesn't exist in HTML), nor does it have a closing tag (because <img>
does not have </img>
).
(To demonstrate this, try console.log(html);
)
As such, the HTML you are trying to parse is... well, just an opening tag. But you're telling it to parse as XHTML+XML, which does not have this rule on <img>
tags.
You could potentially use text/html
as the type of document, however keep in mind that this will generate a bare-bones <html><head></head><body><img></body></html>
structure.