467,207 Members | 1,319 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,207 developers. It's quick & easy.

Is it just 'bad form'?

I don't seem to see the following structure very often ...

<root>
<e1>this
<e2/>
<e3>that</e3>
</e1>
</root>

That is an element with text /and/ child nodes.

Is this just bad form? I know it is OK technically but are there
practical reasons for avoiding doing it?

--
Stuart
Tracers work both ways. - U.S. Army Ordnance

Jul 20 '05 #1
  • viewed: 1341
Share:
8 Replies


DFN-CIS NetNews Service wrote:
I don't seem to see the following structure very often ...

<root>
<e1>this
<e2/>
<e3>that</e3>
</e1>
</root>

That is an element with text /and/ child nodes.

Is this just bad form? I know it is OK technically but are there
practical reasons for avoiding doing it?


Well, with a DTD suched mixed content is hard to restrict. Of course if
you look at XHTML container elements they need to allow such content but
even there the different document types make different restrictions, for
instance with the XHTML 1.0 transitional document type the <body>
element is defined as
<!ELEMENT body %Flow;>
where The Flow entity is defined as
<!ENTITY % Flow "(#PCDATA | %block; | form | %inline; | %misc;)*">
which is the mixed content of text and markup elements.
With the XHTML 1.0 strict document type <body> is defined as
<!ELEMENT body %Block;>
so there no mixed content is allowed, only block elements can be direct
children of the <body>.
With XHTML strict the reasons for that are that they want you to write
clean structured documents where you use proper container block elements
with the right semantics (for instance a <p> element) to wrap your text
content.
Thus looking at that you could say it is bad (but established form) to
have mixed content in every elements but a few selected ones.

As for your example if <e1> contains sentences in some human language
and <e2 /> is some empty element like an <img> element in XHTML and <e3>
is semantically necessary to mark up a part of a sentences contained in
<e1> then it is certainly not bad form but if <e1> contains different
data nodes then I would say that it is bad style to have some data in a
text node and some in element nodes.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
On 20/01/2004, around 11:09, Martin Honnen wrote:

MH> Well, with a DTD suched mixed content is hard to restrict. Of course if
MH> you look at XHTML container elements they need to allow such
MH> content...
[deletia]

Interesting, thanks. In my case I'm talking about XML data rather than
XHTML, but that was useful.

TVM.

--
Stuart
Eat Healthy, Take Exercise, Die Anyway.

Jul 20 '05 #3
DFN-CIS NetNews Service wrote:
I don't seem to see the following structure very often ...

<root>
<e1>this
<e2/>
<e3>that</e3>
</e1>
</root>

That is an element with text /and/ child nodes.

Is this just bad form? I know it is OK technically but are there
practical reasons for avoiding doing it?

It rather depends on what you are using the XML for.
If it is "data-centric" , so being used to show the structure of some
data then it is probably bad form/ poorly designed ;
but if the use is "docu-centric" and so being used to show the mark up
and structure of a visible/readable document where one has a mix of
plain text , graphics and emphasis then it seems quite natural .
--
J. D. Addison

Jul 20 '05 #4
On 20/01/2004, around 11:33, Puff Addison wrote:

PA> If it is "data-centric" , so being used to show the structure of some
PA> data then it is probably bad form/ poorly designed ;
That's precisely it; it /feels/ bad but I can't get a handle on why we
shouldn't be doing it.

I'd rather see something like

<root>
<e1>
<e1_text>this</e1_text>
<e2/>
<e3>that</e3>
</e1>
</root>

IYSWIM.

--
Stuart
If at first you don't succeed, skydiving is not for you.

Jul 20 '05 #5
DFN-CIS NetNews Service wrote:
On 20/01/2004, around 11:33, Puff Addison wrote:

PA> If it is "data-centric" , so being used to show the structure of some
PA> data then it is probably bad form/ poorly designed ;
That's precisely it; it /feels/ bad but I can't get a handle on why we
shouldn't be doing it.

I'd rather see something like

<root>
<e1>
<e1_text>this</e1_text>
<e2/>
<e3>that</e3>
</e1>
</root>

IYSWIM.


Yes. I see what you mean.
If you are creating the mark up then you are free do it that way. But it
is not clear to me that you get any real benefit
unless e1_text is to have some structure of its own but you do add to
the overhead of document creation.
Think of paragraph a number of words or phrases in bold or italic or
courier. Every time I need to add a new e1_text element as well.

--
J. D. Addison

Jul 20 '05 #6
On Tue, 20 Jan 2004 10:29:49 +0000, DFN-CIS NetNews Service
<sh******@estatecomputers.com> wrote:
I don't seem to see the following structure very often ...


I see it a lot, and a damn nuisance it is too.

What are you storing here ? An XML tree structure of "data items",
with leaf nodes that contain a string ? Or a text document, with
embedded markup ?

If it's the first, then avoid this as far as you can. It causes all
sorts of trouble.

If it's the second (which includes (X)HTML) then it's hard to avoid
it. It's possible to avoid it, but only by making the DTD
significantly more complex, to an impractical degree. In the DocBook
world it's known as "pernicious mixed content" and is subject to much
debate.

--
#1A1A1A is the new black
Jul 20 '05 #7
Andy Dingley wrote:
On Tue, 20 Jan 2004 10:29:49 +0000, DFN-CIS NetNews Service
<sh******@estatecomputers.com> wrote:

I don't seem to see the following structure very often ...

I see it a lot, and a damn nuisance it is too.

What are you storing here ? An XML tree structure of "data items",
with leaf nodes that contain a string ? Or a text document, with
embedded markup ?

If it's the first, then avoid this as far as you can. It causes all
sorts of trouble.

If it's the second (which includes (X)HTML) then it's hard to avoid
it. It's possible to avoid it, but only by making the DTD
significantly more complex, to an impractical degree. In the DocBook
world it's known as "pernicious mixed content" and is subject to much
debate.


Pernicious mixed content only exists in SGML, not XML.

///Peter

Jul 20 '05 #8
On Wed, 21 Jan 2004 01:26:41 +0000, Peter Flynn <pe***@silmaril.ie>
wrote:
Pernicious mixed content only exists in SGML, not XML.


Sorry - I should have been clearer.

DocBook is an SGML standard that moved to XML (is it the only major
standard that did this ?). When it was in SGML, then pernicious mixed
content was a real problem. It's still worth reading up on, because
the problem is still there, just watered down. "Pernicious mixed
content" is a more useful search term than "mixed content" for
finding it.

Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Heath | last post: by
10 posts views Thread by cppaddict | last post: by
4 posts views Thread by Bob | last post: by
7 posts views Thread by Tom van Stiphout | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.