XML
Beginner
1 min read
Introduction to Document Type Definitions
Example
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library [
<!-- Root element must contain one or more book elements -->
<!ELEMENT library (book+)>
<!-- book contains: title, author+, year, price? -->
<!ELEMENT book (title, author+, year, price?)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT price (#PCDATA)>
<!--
ATTLIST for book:
id — unique identifier (type ID)
category — enumerated value
available — optional flag, default "true"
-->
<!ATTLIST book
id ID #REQUIRED
category (fiction|non-fiction|reference) #REQUIRED
available (true|false) "true"
>
]>
<library>
<book id="b001" category="non-fiction" available="true">
<title>XML in a Nutshell</title>
<author>Elliotte Rusty Harold</author>
<author>W. Scott Means</author>
<year>2004</year>
<price>39.99</price>
</book>
<book id="b002" category="reference">
<title>XML Schema</title>
<author>Eric van der Vlist</author>
<year>2002</year>
</book>
</library>