On Mar 6, 12:32 pm, "Richard Cornford"
<Rich...@litotes.demon.co.ukwrote:
Other options are available in the creation of a DOM from
mark-up. For example, should the DOM be presented
pre-normalised (in the sense of having no adjacent text
nodes) or not?
I believe you are wrong on this one. The description of
Text interface in DOM Level 2 Core seems rather
uncompromising:
When a document is first made available via the DOM,
there is only one Text node for each block of text. Users
may create adjacent Text nodes that represent the
contents of a given element without any intervening
markup, but should be aware that there is no way to
represent the separations between these nodes in XML or
HTML, so they will not (in general) persist between DOM
editing sessions. The normalize() method on Node merges
any such adjacent Text objects into a single node for
each block of text.
If a DOM was required to be pre-normalised then there
would be little point in defining a - normalise - method
on the Node interface, but that does not mean they will
never be pre-normalized.
The description given above also explains why normalize()
might be useful. The remarks provided for normalize()
method itself give further explanations:
Puts all Text nodes in the full depth of the sub-tree
underneath this Node, including attribute nodes, into a
"normal" form where only structure (e.g., elements,
comments, processing instructions, CDATA sections, and
entity references) separates Text nodes, i.e., there are
neither adjacent Text nodes nor empty Text nodes. This
can be used to ensure that the DOM view of a document is
the same as if it were saved and re-loaded, and is useful
when operations (such as XPointer [XPointer] lookups)
that depend on a particular document tree structure are
to be used.
There's a well-known bug in Gecko engine that *forces* long
chunks of text to be denormalized into 4096 octets long
(defined as a preprocessor constant, and I've seen the
darned thing with my own eyes, too) text nodes. It's been
around for four years at least I believe, and the number of
cardiac arrests it caused is probably counted in dozens,
but the dev team refuses to fix it quoting performance
reasons. The fact that the bug exists and that we've
learned to live with it doesn't yet mean it's standard
behavior, though.
--
Pavel Lepin