[whatwg] DOMParser / XMLSerializer

João Eiras joaoe at opera.com
Wed May 20 16:25:25 PDT 2009


On Wed, 20 May 2009 23:20:34 +0200, Anne van Kesteren <annevk at opera.com> wrote:

> Although it seems most browsers have adopted these APIs, HTML5 offers basically identical APIs in the form of
>
>   document.innerHTML
>
> or is there something that DOMParser / XMLSerializer can do that document.innerHTML cannot?
>
>

XMLSerializer must generate well formed xml (all tags closed, no attributes without values, case preserved, etc) and it accepts a full document, so you get a serialized output with doctype, processing instructions, comments which are not descendants of the root, and the root itself.

DOMParser parses xml into a full document so if I have a doctype subset, those will be recognized and replaced on the document. That does not happen with innerHTML. If the input source has processing instructions, these will be preserved also in the result document.

These are duplicates of the functionality provided on DOM 3 LS, and developer prefer these because their APIs are simpler and more convenient.



More information about the whatwg mailing list