aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML DTD Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML DTD Help" Watch "XML DTD Help" New topic
Author

XML DTD Help

joey mo
Greenhorn

Joined: Mar 31, 2010
Posts: 9
i have a few questions to ask

in Schema i know its possible to use minoccurs and maxoccurs but is there a way to do something similar in DTD?

and another thing

how can you apply date and a zipcode format in dtd?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

No. Read the tutorial I linked to in your other post.

Edit: wait a minute... "something similar"? Yes, you can specify that an element may only occur once, if I'm not mistaken. That's similar I think.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The occurence indicators are + (One is required and it is repeatable), * (Optional, may be one or more), ? (Optional, may be one and only one)

A DTD is to define and validate a particular markup language. So, it validates the structure of the instance document, but does not, and should not, attempt to do any validating or formatting of the data that is marked up with the markup language. This is best left to applications that process the document, rather that a tool to validate it. This supports separation of concerns principles and good software engineering practice.

Now, when some groups somehow felt that content validation should be built into the validation mechanism, the geniuses created the XML Schema Language and built all sorts of ways to validate the "data" in addition to the "markup structure." What this does is tightly couple your application to a schema (bad) and creates a whole mess of things here and things there and things everywhere whenever you have anything but a simple markup language.

In my opinion, XML Schema makes things more confusing. EBNF DTD are fine for validation have been for over 25 years. Keep in mind that XML is only a simplified version of SGML (ISO 8879).

joey mo
Greenhorn

Joined: Mar 31, 2010
Posts: 9
So i could do something like

<!element root (people)>
<!element people (people+,people?,people?,people?,people?)

would this just a make it so there is 1 person and maxium of 5?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
<!ELEMENT root (people)>
<!ELEMENT people (people+,people?,people?,people?,people?)

would this just a make it so there is 1 person and maxium of 5?


No, this is not correct. As mentioned, you cannot control the number of occurences beyond what I mentioned earlier.

If you are using a DTD to parse an instance document and you have a data processing program that does something with the data after it is parsed, then you can write the code in the data processing program to reject the data if it finds more than five occurences of a particular element. This is simple coding.

The alternative is to have this logic in an XML schema. But then you will be tightly coupling your data processing to the schema and will expand the boundary of the data processing logic, i.e. some logic in program and some logic in XML schema.

Aside, if you are just playing around with markup language design, then you can fool around with something like:



This will give you at least one person with the potential to have up to five persons as child elements of the people element.



 
It is sorta covered in the JavaRanch Style Guide.
 
subject: XML DTD Help