Joshua Street wrote:
On 3/13/06, Jay Gilmore <[EMAIL PROTECTED]> wrote:
I have also read (no personal first hand knowledge) that there can be
issues between using DOM/DHTML scripts and XHTML. I don't know what
these issues are but why invite trouble.

This arises from non-DOM methods, which are often much simpler to
implement (and faster in terms of performance), such as innerHTML [1]
(and document.write, but we won't go there). I *think* this is because
innerHTML/outerHTML/document.write and their kin leave the XML tree
alone -- any elements in the inserted content _aren't_ created as
elements, and hence cannot be manipulated at all.

Um... What the? Of course they are created as elements, or at least they should be, unless you're talking about some strange IE bug I'm not aware of. (I never use innerHTML so I'm not aware of all of its quirks.)

AIUI, the way innerHTML is supposed to work is that the value is parsed as HTML or XML (depending on whether the document is HTML or XHTML; which is determined by the MIME type, not the DOCTYPE) and a DOM DocumentFragment is created. If it's XHTML, it should result in an error when the value is not well formed. Mozilla does this, but Opera doesn't because it always parses it as HTML. I'm not sure about other browsers.

All children of the element are then removed from the tree and the new DocumentFragment is appended. I believe Mozilla internally uses its proprietary range.createContextualFrament() function to do this.

(That aside, I don't really see anything wrong with this [innerHTML] -- we must remember that XMLHttpRequest object is also proprietary!)

The problem is not that it's proprietary, there is actually work to get it standardised as part of the WHATWG's Web Apps proposal. The problem I have with it is that it's working with strings to manipulate the DOM, and those strings need to have escaped characters which get's quite messy, much like document.write(), but not quite as bad [1].

For instance, just to write one simple element with an attribute, it needs to be like this:
<script>
  ...
  foo.innerHTML = "<p class=\"bar\">text<\/p>"
  ...
</script>

My other problem with it is that it's specific to (X)HTML, not any generic XML like the rest of the DOM API is (except for, of course, DOM 2 HTML). IMHO, Mozilla's createContextualFragment() is much more useful for any DOM and I would like it to be standardised, but I don't see that happening any time soon.

A much better alternative is to use E4X which is specially designed to make working with XML very easy, as XML is a native data structure, but support is currently too limited for real world usage.

[1] document.write() is bad because of the way it throws more markup back to the parser during parsing which means instead of having a nice flow like this:

input --> parser --> tree constructor --> output (DOM)

document.write() makes it more like this:

input --> parser --> tree constructor --> output (DOM)
         ^                |
         |___doc.write()__|

--
Lachlan Hunt
http://lachy.id.au/
******************************************************
The discussion list for  http://webstandardsgroup.org/

See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************

Reply via email to