Constraining a mixed content model (XHTML <div>)

Discussion in 'XML' started by Mark, Sep 11, 2005.

  1. Mark

    Mark Guest

    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
     
    Mark, Sep 11, 2005
    #1
    1. Advertising

  2. Mark

    Peter Flynn Guest

    Mark wrote:

    > 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
     
    Peter Flynn, Sep 13, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kwaj
    Replies:
    1
    Views:
    642
    David Bishop
    Apr 25, 2004
  2. Replies:
    1
    Views:
    639
    Eliyahu Goldin
    Apr 17, 2005
  3. David Valera
    Replies:
    0
    Views:
    482
    David Valera
    May 10, 2005
  4. Bryan Ax
    Replies:
    6
    Views:
    558
    Peter Flynn
    May 17, 2006
  5. =?Utf-8?B?bXVzb3NkZXY=?=

    AccessDataSource constraining results?

    =?Utf-8?B?bXVzb3NkZXY=?=, Feb 20, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    503
    Steven Cheng[MSFT]
    Feb 22, 2007
Loading...

Share This Page