W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2012

Re: [whatwg] Proposal for window.DocumentType.prototype.toString

From: Johan Sundström <oyasumi@gmail.com>
Date: Tue, 30 Oct 2012 23:00:49 -0700
Message-ID: <CAGFhi3-PZC_=7Btw4qkLvo9v1s+3uEHsaoGrsWyqqxAtOwxKaw@mail.gmail.com>
To: Stewart Brodie <stewart.brodie@antplc.com>
Cc: whatwg@whatwg.org
On Tue, Oct 30, 2012 at 3:20 AM, Stewart Brodie
<stewart.brodie@antplc.com> wrote:
>> Hi everybody!
>>
>> Serializing a complete HTML document DOM to a string is surprisingly
>> hard in javascript.
>
> Does XMLSerializer().serializeToString(document) not meet your requirement?

Ah – good thinking. (new XMLSerializer).serializeToString(document)
does indeed do a pretty excellent job of it, including the crazy hacks
people do with conditional comments outside of the root node, which I
hadn't figured I would be able to piece back together from an already
parsed page.

While I hate to admit it, maybe on some level there is benefit to much
of the DOM APIs being javascript hostile to force you towards the
occasional really well-paved paths like the above, when you can find
them.

My use case was taking as good a snapshot of an already live web
page's structure from a non-privileged bookmarklet, for archival
purposes (i e essentially what a curl of the page would do). For my
purposes, it is a bonus that I actually get the current state of the
page with whatever DOM mods have transpired since it loaded rather
than what curl would produce, so I think XMLSerializer is a good
friend.

That said, I would still much enjoy a future where
javascript:alert(document.doctype) would tell you something rich about
the page that we today need deep knowledge of document.compatMode
and/or combinations of XMLSerializer and parsers, or deep study of
DocumentType refdocs to tease out.

Is there a case against it in people using it where they ought to pick
other solutions?

-- 
 / Johan Sundström, http://ecmanaut.blogspot.com/

> --
> Stewart Brodie
> Team Leader - ANT Galio Browser
> ANT Software Limited
Received on Wednesday, 31 October 2012 06:01:20 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:11 GMT