XHTML Orphaned text representation in a DOM

M

Mike

If you have the following xhtml fragment
<div>
Some text
</div>

This will be an element with innerText of "Some text".

But in the case of
<div>
Some text
<span>blah blah</span>
Some more text
</div>

How is this represented in a DOM? The <span> should be a child element
- are the "Some text" and "Some more text" sibling elements, and if
so, what type of element?
 
P

Pavel Lepin

Mike said:
<div>
Some text
<span>blah blah</span>
Some more text
</div>

How is this represented in a DOM? The <span> should be a
child element - are the "Some text" and "Some more text"
sibling elements,

Sibling nodes of 'span' element, not sibling elements. And
child nodes of 'div' element.
and if so, what type of element?

Those are text nodes, obviously. The fragment above
represents the following tree (ignoring
not-particularly-meaningful whitespace):

[element] div
|
`-[text node] "Some text"
|
`-[element] span
| |
| `-[text node] "blah blah"
|
`-[text node] "Some more text"
 
P

Peter Flynn

Pavel said:
Sibling nodes of 'span' element, not sibling elements. And
child nodes of 'div' element.

And in general, don't do this at the div level. It'll make your teeth
fall out, give you white hair, and end in tears and recriminations.
Where possible, use better markup:

<div>
<p>Some text
<span>blah blah</span>
Some more text</p>
</div>

Dangling mixed content (what you described) needs to be avoided.

///Peter
 
P

Pavel Lepin

Peter Flynn said:
And in general, don't do this at the div level. It'll make
your teeth fall out, give you white hair, and end in tears
and recriminations. Where possible, use better markup:

<div>
<p>Some text
<span>blah blah</span>
Some more text</p>
</div>

Dangling mixed content (what you described) needs to be
avoided.

Pardon my bluntness, but to me that looks silly and
superfluous; and it doesn't get rid of "dangling" text
nodes even if getting rid of them in document markup was a
good idea. Stuffing a p into a div looks weird--why would
you need a div then? It's just a block element with no
additional semantics. If you want a paragraph, use a p.

The entire "one text node per element" idea just doesn't
make much sense (in context of document markup, as opposed
to data markup), unless for some inexplicable reason you
want to stuff everything with default semantics into a
span; and that doesn't even work, because of the way
whitespace is handled in XHTML, and because of Gecko's
peculiar idiosyncrasies where long text nodes in DOM are
concerned.
 
J

Joe Kesselman

Pavel said:
The entire "one text node per element" idea just doesn't
make much sense (in context of document markup, as opposed
to data markup), unless for some inexplicable reason you
want to stuff everything with default semantics into a
span; and that doesn't even work, because of the way
whitespace is handled in XHTML, and because of Gecko's
peculiar idiosyncrasies where long text nodes in DOM are
concerned.

Agreed. Avoiding mixed content may make sense for specific applications,
but (a) the proposed change doesn't do that, and (b) it really isn't
either viable or necessary as a general rule of thumb.

XML tools handle text siblings with no trouble. If a specific
application doesn't, then when you design the dedicated XML language
which goes with that application you can consider whether the XML should
reflect that limitation.

Note that the old argument for avoiding mixed content (that DTDs
couldn't constrain the order of element children in mixed content) goes
away when using schemas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top