DTD Logic

Discussion in 'XML' started by johnlittlepeap, Feb 25, 2004.

  1. how do all,

    I have an xml file, for example
    <content>
    <section/>
    <section/>
    <on/>
    <off/>
    </content>

    Obviously just an example. I would like the dtd to say, the xml file
    must have one or more section, 0-1 on tags, 0-1 off tags and that the
    on and off tags can be in any order. Try as I may I havn't been able
    to uncover the syntax to define this.

    I have at the moment

    <!ELEMENT content (section+,on+,off+>

    but the commas say they must be in that particular order, my xml files
    aren't like this. I want to be pretty much as it is here, except that
    they don't have to be in order. I don't want to just say ANY. Any help
    would be appreciated

    Troot
    johnlittlepeap, Feb 25, 2004
    #1
    1. Advertising

  2. You can use alternation to get the order independence like so:

    <!ELEMENT content (section|on|off)*>

    But this does not solve your number-of-occurences constraint. Here is
    another variation that ensures that the section is up front... still
    does not strictly solve your number-of-occurences constraint:

    <!ELEMENT content (section*, (on?|off?)*)>

    To solve the constraint along with the order independence constraint,
    you probably just need to do it by brute force:

    <!ELEMENT content (section*, (on|off|(on,off)|(off,on)))>


    johnlittlepeap wrote:
    > how do all,
    >
    > I have an xml file, for example
    > <content>
    > <section/>
    > <section/>
    > <on/>
    > <off/>
    > </content>
    >
    > Obviously just an example. I would like the dtd to say, the xml file
    > must have one or more section, 0-1 on tags, 0-1 off tags and that the
    > on and off tags can be in any order. Try as I may I havn't been able
    > to uncover the syntax to define this.
    >
    > I have at the moment
    >
    > <!ELEMENT content (section+,on+,off+>
    >
    > but the commas say they must be in that particular order, my xml files
    > aren't like this. I want to be pretty much as it is here, except that
    > they don't have to be in order. I don't want to just say ANY. Any help
    > would be appreciated
    >
    > Troot
    Charles Fineman, Feb 25, 2004
    #2
    1. Advertising

  3. On Wed, 25 Feb 2004 07:57:17 +0000, Charles Fineman wrote:

    > You can use alternation to get the order independence like so:
    >
    > <!ELEMENT content (section|on|off)*>
    >
    > But this does not solve your number-of-occurences constraint. Here is
    > another variation that ensures that the section is up front... still
    > does not strictly solve your number-of-occurences constraint:
    >
    > <!ELEMENT content (section*, (on?|off?)*)>
    >
    > To solve the constraint along with the order independence constraint,
    > you probably just need to do it by brute force:
    >
    > <!ELEMENT content (section*, (on|off|(on,off)|(off,on)))>


    That is actually not valid, because the content model is ambigous, which
    is one of the more esoteric errors one can make in DTD design. Also, he
    wanted "section" to be mandatory. I'd recommend:

    <!ELEMENT content (section+, ((on,off?)?|off?)) >

    Of course in an SGML DTD it would simply be:

    <!ELEMENT content (section+, (on? & off?)) >

    but the XML designers thought that no one ever really wants to use the "&"
    connector.

    Oliver
    Oliver Bonten, Feb 25, 2004
    #3
  4. On Wed, 25 Feb 2004 19:13:23 +0100, Oliver Bonten wrote:

    > On Wed, 25 Feb 2004 07:57:17 +0000, Charles Fineman wrote:
    >
    >> You can use alternation to get the order independence like so:
    >>
    >> <!ELEMENT content (section|on|off)*>
    >>
    >> But this does not solve your number-of-occurences constraint. Here is
    >> another variation that ensures that the section is up front... still
    >> does not strictly solve your number-of-occurences constraint:
    >>
    >> <!ELEMENT content (section*, (on?|off?)*)>
    >>
    >> To solve the constraint along with the order independence constraint,
    >> you probably just need to do it by brute force:
    >>
    >> <!ELEMENT content (section*, (on|off|(on,off)|(off,on)))>

    >
    > That is actually not valid, because the content model is ambigous, which
    > is one of the more esoteric errors one can make in DTD design. Also, he
    > wanted "section" to be mandatory. I'd recommend:
    >
    > <!ELEMENT content (section+, ((on,off?)?|off?)) >


    I hate to correct myself, but probably

    <!ELEMENT content (section+, ((on,off?)?|(off,on?)?)) >

    would be more useful.

    Oliver
    Oliver Bonten, Feb 25, 2004
    #4
  5. ah, I have more tags that need to have the same rule applied as on and
    off. With only a couple more tags this becomes completly unworkable.
    Thanks though for helping me. To be honest I thought something like
    this might be the answer. Just hoped it wasn't.

    Thanks

    Troot

    > I hate to correct myself, but probably
    >
    > <!ELEMENT content (section+, ((on,off?)?|(off,on?)?)) >
    >
    > would be more useful.
    >
    > Oliver
    johnlittlepeap, Feb 26, 2004
    #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. Lloyd Dupont

    WebCustomControl & DTD

    Lloyd Dupont, Aug 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    299
    Lloyd Dupont
    Aug 8, 2003
  2. Joseph Tilian
    Replies:
    0
    Views:
    337
    Joseph Tilian
    Dec 21, 2004
  3. Ronald Fischer
    Replies:
    4
    Views:
    1,741
    Ronald Fischer
    Mar 17, 2005
  4. test
    Replies:
    2
    Views:
    1,984
    Oliver Wong
    Jul 28, 2006
  5. spike
    Replies:
    8
    Views:
    1,433
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page