Below is an example of XML file and the corresponding DTD file. This XML file has "card" as a root element and "fname", "lname", "heading", "title" as children elements. "Title" element also has an attribute "id" with a value of "30".
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE card SYSTEM "card.dtd">
<card>
<fname>Tove</fname>
<lname>Jani</lname>
<heading>Business Card</heading>
<title id="30">Consultant</title>
</card>
Below is a Document Type Definition file which defines structure of the XML file above. This DTD file defines top level "card" element which must have "fname", "lname", "heading", "title" elements as children. "Title" element has "id" attribute defined.
<!DOCTYPE card
[
<!ELEMENT card (fname,lname,heading,title)>
<!ELEMENT fname (#PCDATA)>
<!ELEMENT lname (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ATTLIST title id CDATA "0">
]>
Download this XML example file and corresponding card.dtd file.
XML Quick Info | |
---|---|
Extensible Markup Language | |
MIME Type | |
text/xml | |
Opens with | |
Microsoft XML Notepad | |
XmlPad | |
Altova XMLSpy | |
XEditor |