Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

DTD Example (XML Bible)

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Suppose I am writing a DTD to have between 4 and 6 TEAM elements for a DIVISION element, how do I go about specifying this ?
Please note - I cannot have three nor seven TEAM elements for the DIVISION in my Document, such a document must be forced to be treated as invalid.
Hint : I can try to enforce the same above by grouping TEAM elements in a sequence, but still, I have cracked this to atleast
have 4 elements but not the second criterion
Please get back with your suggestions.
Thanks and Regards,
Praveen Zala
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AFAIK, DTD cannot support restricting the number of elements. The only thing you can do is specify very generic cardinality - zero or more, one or more or zero or one. Given your requirements, these are not going to be of any use.
You have two options -

  • [list] Validate the document while parsing. This is fairly easy to do.
  • Create more than one TEAM elements that captures your restriction. For instance

    With these two definition, you can define a <DIVISION> as an element that contains either </TEAMOF_4> or </TEAMOF_6>.
    I accept this is not a very clean design given and introduces redundancy especially for <MEMBERx> elements, but it works!
    Let me know if you have a better idea!
    Cheers!
    ------------------
    Ajith Kallambella M.
    Sun Certified Programmer for the Java�2 Platform.
    IBM Certified Developer - XML and Related Technologies, V1.
    [This message has been edited by Ajith Kallambella (edited September 27, 2001).]
  •  
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Can you use a schema instead of a dtd?
    If so you could use the minOccurs and maxOccurs attributes to specify exactly what you want. Something like this:
    <element name="division">
    <complexType>
    <element name="team" type="string"
    minOccurs="4" maxOccurs="6"/>
    </complexType>
    </element>
     
    Ajith Kallambella
    Sheriff
    Posts: 5782
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Angie - eventhough it might seem like a good solution, the minOccurs="4" maxOccurs="6" constraing would allow 5 member teams too! I guess that would be wrong as per the initial requirement of allowing only 4 member and 6 member teams.
    Right?
     
    Angie Lathum
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I thought the requirement was to have "between 4 and 6", so I thought 5 was wanted as valid also.
    Anyway, I also found another way to do it with a dtd (and if 5 isn't wanted you can just leave the middle line out

    <!ELEMENT division (
    (team, team, team, team) |
    (team, team, team, team, team) |
    (team, team, team, team, team, team)>

    Its not very elegant, but I guess it would work.
    Angie
     
    Leverager of our synergies
    Posts: 10065
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Yeah... And you may want to read this: http://www.xml.com/pub/a/2001/09/26/q-and-a.html
     
    Praveen Zala
    Ranch Hand
    Posts: 118
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you all for your responses.
    I had posted this on the XML Developer's Forum and look at some of the responses I got :
    a) <!ELEMENT DIVISION (TEAM,TEAM,TEAM,TEAM,(TEAM,TEAM?)?) >
    b) Use a Schema instead of a DTD.
    <xsd:element name="team"
    minoccurs="4"
    maxoccurs="6"
    type="xsd:string" />

    Thanks and Regards,
    Praveen Zala
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic