Re: childNodes.length IE and FF difference



Ian Collins wrote:
Michael Winter wrote:
[...]
As Firefox doesn't typically use a validating XML processor, white space
in element content will be treated simply as character data, and the DOM
Core Level 2 specification states in the introductory section, "What the
Document Object Model is":

Note: There may be some variations depending on the parser
being used to build the DOM. For instance, the DOM may not
contain whitespaces in element content if the parser discards
them.

So, conversely, if the parser does pass on white space characters (and
we've established that it may), the document tree may contain the text
nodes that Fx includes.

With applications of SGML, the situation is different as there are rules
for collapsing white space and ignoring line terminators after start
tags and before end tags. White space in element content may also need
to be ignored, but as I don't have a copy of the SGML specification, I
couldn't say for certain.

I think that's the cause of the difference, IE parses XML as HTML thus
collapses the whitespace.

Is that an excuse? I thought the HTML specification dealt with white space from the perspective of presentation, not a DOM.

For example, some written languages require that all white space is removed and others do not so it would be silly to remove it from the DOM depending on the language used.

I thought that whitespace should be preserved because if CSS is to be used to display content, you can't remove whitespace (other than collapsing it) that might be required by CSS, so better to preserve it and let CSS do its thing.

There is a concept of treating white space in block and inline elements differently, but CSS block elements can become inline and vice versa, so again at the DOM level it would be silly to remove whitespace based on a node being a block element when it might be later changed to inline (or some other display attribute value).


--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>
.



Relevant Pages

  • Re: element.children.length v/s element.childNodes.length
    ... That almost certainly represented a seriously flawed attempt to be compatible with IE browsers without going to the effort of writing a truly compatible - children - collection object, but it is still part of the reality that would suggest leaving the - children - alone and concentrating on the more predictable - childNodes - whenever available. ... Strictly that should be ' ignores text nodes that contain "non-significant" white space. ... Non-significant white space might be, for example, a carriage return between the closing and opening tags of two consecutive block elements, and be non-significant because it would not influence the rendering of the document. ... This behaviour is a feature of DOM parser software and the pertinent specs for that software makes the representation of non-significant white space optional. ...
    (comp.lang.javascript)
  • RE: Differences in XSL Transform between dotnet and MSXML
    ... XSL Transformations uses the XML Document Object Model (DOM), ... the source document, to guide its transformation. ... has already been stripped to process the XML into the DOM, white space ... characters are lost even before the transformation takes place. ...
    (microsoft.public.dotnet.general)
  • Re: DOM question
    ... > just get a DOM Text node with a few white space in ... Welcome to the wonderful world of DOM, ... Use XPath. ... It's well worth the effort, as it is suited for exactly ...
    (comp.lang.python)
  • Re: Event Handling via CSS
    ... JavaScript event handlers via css for CSS attributes like "hover"? ... It may also, rather independently of the DOM, trigger a style sheet selector ... that uses a dynamic pseudo-class. ... HTML elements provide event-handler attributes which value is supposed to be ...
    (comp.lang.javascript)
  • Re: firefox onmouseover frame focus problem
    ... implement this part of W3C DOM Level 2 Core, ... a valid object reference always returns to `true'. ... And there is an additional CSS alternative for conforming user agents ... independent of the color depth of the readers's display. ...
    (comp.lang.javascript)