[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: newbie-ish DTD question: am i asking too much of XML, or of my brain
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)> --or-- <!ELEMENT link EMPTY> 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)> ]> <model>...</model> 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"> <model>...</model> -- Ron Bourret xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i... Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1 To (un)subscribe, mailto:majordomo@i... the following message; (un)subscribe xml-dev To subscribe to the digests, mailto:majordomo@i... the following message; subscribe xml-dev-digest List coordinator, Henry Rzepa (mailto:rzepa@i...)
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|