External DTDs

Before the DTD gets any bigger, let's go ahead and move it out to its own document, as we did with the style sheets. First, we'll create the DTD file itself and call it products.dtd. We'll save it in the same directory as products.xml. As shown in Listing 3.9, we're keeping the content the same, but this file doesn't include the <!DOCTYPE> declaration that was in the products.xml file.

Listing 3.9. Creating an External DTD
 0: <!ELEMENT products (vendor)+> 1: 2: <!ELEMENT vendor (vendor_name, advertisement?, product*)> 3: <!ATTLIST vendor webvendor CDATA #REQUIRED> 4: 5: <!ELEMENT vendor_name (#PCDATA)> 6: 7: <!ELEMENT advertisement (ad_sentence)+> 8: <!ELEMENT ad_sentence (#PCDATA | b | i | p )*> 9: <!ELEMENT b (#PCDATA)> 10:<!ELEMENT ...

Get XML and Java™ from scratch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.