Chapter 3
Defining XML: DTDs
Examples
- Example 3-1
- Example 3-2: XML DTD
- Example 3-3: XML DTD
- Example 3-4: XML DTD
- Example 3-5: XML DTD
- Example 3-6
- Example 3-7: XML DTD entity
- Example 3-8: DTD entity
- Download all Chapter 3 code (chapter3.zip)
What are DTDs?
DTDs are files or chunks of code that determine how some XML must be structured and the names of all the tags and attributes that can be used.
Here are some examples of defining an element:
<!ELEMENT shirt_list (shirt*)>
<!ELEMENT shirt (size, color)>
<!ELEMENT size (#PCDATA)>
<!ELEMENT color (#PCDATA)>
<!ELEMENT shirt (size, color)>
<!ELEMENT size (#PCDATA)>
<!ELEMENT color (#PCDATA)>
and some examples of how to define an attribute:
<!ATTLIST shirt quantity CDATA #IMPLIED>
<!ATTLIST shirt quantity CDATA #REQUIRED>
<!ATTLIST shirt quantity CDATA "1">
<!ATTLIST shirt quantity CDATA #REQUIRED>
<!ATTLIST shirt quantity CDATA "1">