Re: Document.parseHTML(txt) - Why not?

Marcus wrote:

> Such hypothetical method, the return of which would be a DocumentFrament
> object, would look like this ( assume a ECMA262 enviroment ):

> docFrag=doc.parseHTML(str)

DOM Level 3 Load can already do this. See:

   http://www.w3.org/TR/DOM-Level-3-LS/

- albeit with a somewhat more verbose syntax. If you prefer the above 
style you can wrap it in such a function:

   function parseHTML(document, stringData) {
     var fragment= document.createDocumentFragment();

     if (document.implementation.hasFeature('LS', null)) {
       var parser= document.implementation.createLSParser(1, null);
       var input= document.implementation.createLSInput();
       input.stringData= stringData;
       parser.parseWithContext(input, fragment, 1);
     }

     else if (fragment.innerHTML=='')
       fragment.innerHTML= stringData;

     return fragment;
   }

- including support for the 'innerHTML' way of doing it as DOM 3 LS is 
too new to expect much browser support yet.

[aside: it would be nice to think browser manufacturers would manage to 
implement LS without introducing another load of security bugs...]

> ( obs.: the reverse method, docFragTxt=doc.parseStr(docFrag) would,
> likewise, exist ).

See also LSSerializer.writeToString.

-- 
Andrew Clover
mailto:and@doxdesk.com
http://www.doxdesk.com/

Received on Monday, 8 March 2004 15:06:03 UTC