XSD equivalent code to this DTD code?

41 Views Asked by At

Assume that my DTD code have this following listing:

<!ELEMENT body
  ((verse, bridge?, chorus)+) , coda)>

Can I write XSD code, which defines that a sequence of three element (one optional) can be repeated one or more? If it can, what's the listing for that XSD?

1

There are 1 best solutions below

0
C. M. Sperberg-McQueen On

It's true, as Jim Garrison has pointed out in a comment, that the DTD and XSD schema languages are not 1:1 equivalent. But XSD was designed to be able to define any language that can be defined by a DTD (modulo some things like hard-coding namespace prefixes, which were regarded as flaws rather than capabilities of DTDs).

So the short answer to your question is yes, you can write equivalent XSD declarations.

For the long answer, you will want to consult a tutorial on XSD (most question answerers on Stack Overflow will be happy to help you correct errors in your attempts to solve the problem, but not to solve it for you -- there are of course exceptions); the tutorial in Part 0 of XSD 1.0 is accurate and accessible. You will want to pay particular attention to the xsd:sequence and xsd:element elements, and to the minOccurs and maxOccurs attributes on those elements.