More flexible DTD solution needed

Discussion in 'XML' started by Collin VanDyck, Jan 28, 2005.

  1. Hello!

    I'm relatively new to writing DTDs, so be gentle with me :)

    I'm writing a DTD to validate XML documents that script my product which
    managed XHTML.

    I want to use the DTD to enforce basic, high level structure but I don't
    want to account for every single type of element that could be in the
    script document.

    For instance, I want to allow this:

    <script>
    <add-page>
    <name>testPage</name>
    <content>
    ALL SORTS OF XHTML CONTENT GOES HERE
    </content>
    </add-page>
    </script>

    In my DTD I specify the rules for the script, add-page, name, and
    content elements. However, I want to allow all sorts of markup in the
    content element without having to account for it in the DTD.

    In other words, if the user supplies:

    <script>
    <add-page>
    <name>testPage</name>
    <content>
    <b>Hi!</b>
    </content>
    </add-page>
    </script>

    Then I get an error when validating because 'b' was not defined as an
    element.

    Any ideas, or is this not possible using DTD ?

    thanks,
    Collin
    Collin VanDyck, Jan 28, 2005
    #1
    1. Advertising

  2. Collin VanDyck

    Peter Flynn Guest

    Collin VanDyck wrote:

    > Hello!
    >
    > I'm relatively new to writing DTDs, so be gentle with me :)
    >
    > I'm writing a DTD to validate XML documents that script my product which
    > managed XHTML.
    >
    > I want to use the DTD to enforce basic, high level structure but I don't
    > want to account for every single type of element that could be in the
    > script document.


    You can't. Validation means accounting for every single element.

    > For instance, I want to allow this:
    >
    > <script>
    > <add-page>
    > <name>testPage</name>
    > <content>
    > ALL SORTS OF XHTML CONTENT GOES HERE
    > </content>
    > </add-page>
    > </script>


    That's different. Depending on what you really mean, you could either

    a) write a DTD which allowed XHTML mixed content, equivalent to the
    content model for P, for example

    b) write a DTD which allowed any arbitrary mix of XHTML element types
    (so it would never actually be valid XHTML in there, just a jumble.

    (a) is easy. (b) is not so easy, because you still have to declare the
    element types and provide them with content models.

    > Any ideas, or is this not possible using DTD ?


    You either want valid XML or you don't. If you want it valid, it has to
    conform to a DTD or Schema, so you have to write one which it can be
    validated against. If you don't want to do that, you can't have valid
    XML, just well-formed XML. Your call.

    ///Peter
    --
    "The cat in the box is both a wave and a particle"
    -- Terry Pratchett, introducing quantum physics in _The Authentic Cat_
    Peter Flynn, Jan 28, 2005
    #2
    1. Advertising

  3. In article <QrtKd.37899$>,
    Collin VanDyck <> wrote:
    >Any ideas, or is this not possible using DTD ?


    Right, it's not possible.

    It can be done with XML Schemas though.

    -- Richard
    Richard Tobin, Jan 28, 2005
    #3
  4. "Richard Tobin" <> wrote in message
    news:ctejju$2g6v$...
    > In article <QrtKd.37899$>,
    > Collin VanDyck <> wrote:
    >>Any ideas, or is this not possible using DTD ?

    >
    > Right, it's not possible.
    >
    > It can be done with XML Schemas though.
    >
    > -- Richard


    Richard, can you explain this point with more details ?
    Please... ;-)

    Tommaso
    Tommaso Torti, Jan 31, 2005
    #4
  5. In article <41fe19dc$0$6298$>,
    Tommaso Torti <> wrote:

    >> It can be done with XML Schemas though.


    >Richard, can you explain this point with more details ?


    XML Schemas allow you to use a "wildcard" that matches any element,
    and you can specify whether the subtree rooted at that element should
    be validated.

    For an introduction to XML Schemas see

    http://www.w3.org/TR/xmlschema-0/

    -- Richard
    Richard Tobin, Jan 31, 2005
    #5
    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. =?Utf-8?B?RGV2aW4=?=

    More flexible programs for the design of a page

    =?Utf-8?B?RGV2aW4=?=, Jun 1, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    312
    John Oakes
    Jun 1, 2004
  2. Frank Zheng

    how to make my log more flexible?

    Frank Zheng, Oct 20, 2003, in forum: Python
    Replies:
    2
    Views:
    282
    nobody
    Oct 20, 2003
  3. Antoon Pardon

    A more flexible formatting proposal

    Antoon Pardon, May 6, 2004, in forum: Python
    Replies:
    0
    Views:
    288
    Antoon Pardon
    May 6, 2004
  4. , India
    Replies:
    17
    Views:
    1,057
    James Kanze
    Oct 1, 2007
  5. Joe

    A more flexible HyperlinkColumn is needed.

    Joe, Feb 18, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    113
    Alvin Bruney [MVP]
    Mar 2, 2004
Loading...

Share This Page