DTD Logic

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • johnlittlepeap

    #1

    DTD Logic

    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+,o ff+>

    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

    #2
    Re: DTD Logic

    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:[color=blue]
    > 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+,o ff+>
    >
    > 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[/color]

    Comment

    • Oliver Bonten

      #3
      Re: DTD Logic

      On Wed, 25 Feb 2004 07:57:17 +0000, Charles Fineman wrote:
      [color=blue]
      > 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)))>[/color]

      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

      Comment

      • Oliver Bonten

        #4
        Re: DTD Logic

        On Wed, 25 Feb 2004 19:13:23 +0100, Oliver Bonten wrote:
        [color=blue]
        > On Wed, 25 Feb 2004 07:57:17 +0000, Charles Fineman wrote:
        >[color=green]
        >> 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)))>[/color]
        >
        > 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 ?)) >[/color]

        I hate to correct myself, but probably

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

        would be more useful.

        Oliver

        Comment

        • johnlittlepeap

          #5
          Re: DTD Logic

          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
          [color=blue]
          > I hate to correct myself, but probably
          >
          > <!ELEMENT content (section+, ((on,off?)?|(of f,on?)?)) >
          >
          > would be more useful.
          >
          > Oliver[/color]

          Comment

          Working...