Constraining a mixed content model (XHTML <div>)

M

Mark

In XHTML, several elements, such as <div>, may contain what's called
mixed content. Here's the mixed content model for <div>:

<!ELEMENT div (#PCDATA | %Block.class; | %Inline.class;)*>

%Block.class; includes several block-level (structural) elements, and
%Inline.class includes several inline-level (text) elements.

It can lead to strange results which are valid. For example, the
following is valid XHTML:

<div>
Some text.<p>Some more text.</p> And <i>more</i> text.
</div>


I'd like to constrain the DTD content model so <div> can have one
and only one of the following:

Either 1) (%Block.class)*
Or 2) (#PCDATA | %Inline.class;)*

(That is, the mixed content example given above will not validate to
the constrained DTD content model I'd like.)

For the desired constraint, does the following content model work?

<!ELEMENT div (((%Block.class)*) | ((#PCDATA | &Inline.class;)*))>

It seems correct to me, but I often get surprised when I play around
with complex DTD content models (and the above is not that complex --
some of them are absolutely horrid.)

Thanks!

Mark
 
P

Peter Flynn

Mark said:
In XHTML, several elements, such as <div>, may contain what's called
mixed content. Here's the mixed content model for <div>:

<!ELEMENT div (#PCDATA | %Block.class; | %Inline.class;)*>

%Block.class; includes several block-level (structural) elements, and
%Inline.class includes several inline-level (text) elements.

It can lead to strange results which are valid. For example, the
following is valid XHTML:

<div>
Some text.<p>Some more text.</p> And <i>more</i> text.
</div>


I'd like to constrain the DTD content model so <div> can have one
and only one of the following:

Either 1) (%Block.class)*
Or 2) (#PCDATA | %Inline.class;)*

Unfortunately you can't do that in an XML DTD, only in an SGML one.
(That is, the mixed content example given above will not validate to
the constrained DTD content model I'd like.)

For the desired constraint, does the following content model work?

<!ELEMENT div (((%Block.class)*) | ((#PCDATA | &Inline.class;)*))>

No. In any nested content model containing PCDATA, the #PCDATA
must come first. XML Spec, 3.2.2 Mixed Content, [51].
It seems correct to me, but I often get surprised when I play around
with complex DTD content models (and the above is not that complex --
some of them are absolutely horrid.)

Mixed content holds some suprises for the unwary :)
You may be able to fake this up in a Schema.

///Peter
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top