html icon indicating copy to clipboard operation
html copied to clipboard

Interface of returned document with parseFromString(.., "text/xml")

Open emilio opened this issue 5 months ago • 7 comments

What is the issue with the HTML Standard?

It's not clear from https://html.spec.whatwg.org/#dom-domparser-parsefromstring what the interface of the returned document should be.

We have this test written by @Ms2ger which asserts that the returned document is a Document, but not an XMLDocument. All browsers fail it: https://wpt.fyi/results/domparsing/DOMParser-parseFromString-xml.html

The spec should probably be clarified and the test fixed? Happy to do the later, not sure what the right way of doing the former would be but happy to do so with some guidance.

cc @annevk

emilio avatar Jun 11 '25 21:06 emilio

This is just a general case of the specification ecosystem not acknowledging the existence of HTMLDocument and XMLDocument, right? https://github.com/whatwg/dom/issues/221

@foolip was looking into this.

domenic avatar Jun 12 '25 01:06 domenic

Using XMLDocument here seems like clearly the right thing. Fixing everything around the document interfaces at once is a big lift, but maybe the spec could be updated to acknowledge that XMLDocument is real (not an alias) and this specific creation site is fixed?

foolip avatar Jun 12 '25 11:06 foolip

I think once you acknowledge it is real you will surface the other questions, such as whether it's different from Document in any observable way. So I'm not sure how we can make that change without introducing confusion around that. Especially for implementers of new engines.

annevk avatar Jun 12 '25 13:06 annevk

I was mistaken, https://dom.spec.whatwg.org/#xmldocument already acknowledges it exists. So all those questions already arise.

Given that I would be okay with updating the return value to be XMLDocument instead.

annevk avatar Jun 13 '25 13:06 annevk

Is HTMLDocument defined anywhere?

emilio avatar Jun 13 '25 15:06 emilio

Yeah, https://html.spec.whatwg.org/multipage/nav-history-apis.html#htmldocument

Ms2ger avatar Jun 13 '25 15:06 Ms2ger

Ah, I grepped for interface HTMLDocument, of course... Thanks!

emilio avatar Jun 13 '25 17:06 emilio