newbie-ish DTD question: am i asking too much of XML, or of my brain?

Ronald Bourret rbourret at
Tue Sep 21 19:39:51 BST 1999

Rick Wayne wrote:

> i want my documents to consist of a "model" element.  a model can
> contain "topics" and "links", any number, in any order.  in turn, topics
> can contain topics and links, in any number, in any order.
> in (attempted) XML, with ATTLIST tags removed:
> <?XML version="1.0" encoding="UTF-8" standalone="no"?>
> <!ELEMENT model (topic* link*)>
> <!ELEMENT topic (topic* link*)>
> <!ELEMENT link>

Very close, but no cigar.  In a content model with multiple entries, the 
entries must be separated by a pipe symbol (|) (for choices) or a comma 
(for sequences). However, just putting in one of these won't give you what 
you want. For example:

   <!ELEMENT model (topic* | link*)>

means you can have either a bunch of topics or a bunch of links. Instead, 
what you need to do is put the zero-or-more operator (*) on the content 
group as a whole and a pipe between:

  <!ELEMENT model (topic | link)*>
  <!ELEMENT topic (topic | link)*>

Furthermore, you need to declare a content model for the link element, such 
as PCDATA (contains text) or EMPTY (contains nothing). For example:

  <!ELEMENT link (#PCDATA)>

Finally, you need to put your entire DTD in the internal subset (inside the 
DOCTYPE statement) or in an external DTD. For example, here's your DTD in 
the internal subset:

  <?XML version="1.0" encoding="UTF-8" standalone="no"?>
  <!DOCTYPE model [
     <!ELEMENT model (topic | link)*>
     <!ELEMENT topic (topic | link)*>
     <!ELEMENT link (#PCDATA)>

And here's your DTD in an external DTD.

     <!ELEMENT model (topic | link)*>
     <!ELEMENT topic (topic | link)*>
     <!ELEMENT link (#PCDATA)>

Assuming the external DTD file was named model.dtd and that file was in the 
same directory as your XML document, you could reference it from a DOCTYPE 
statement as follows:

  <?XML version="1.0" encoding="UTF-8" standalone="no"?>
  <!DOCTYPE model SYSTEM "model.dtd">

-- Ron Bourret

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at
Archived as: and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at

More information about the Xml-dev mailing list