<?xml version="1.0" encoding="ISO-8859-1"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don 't forget me this weekend!</body></note>
A valid XML document is a "well-formed" XML document, which also conforms to the rules of the Document Type Definition (DTD):
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE note SYSTEM "Note.dtd"><note><to>Tove</to><from>Jani</from>< heading>Reminder</heading><body>Don't forget me this weekend!</body></note>
In the above example, the DOCTYPE declaration is a reference to an external DTD file. The following paragraphs show the contents of this file.
The purpose of a DTD is to define the structure of an XML document. It uses a series of legal elements to define the document structure:
<!DOCTYPE note[<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>]>
If you want to learn DTD, please find DTD tutorials on our home page.
The W3C supports an XML-based replacement for DTD called XML Schema:
<xs:element name="note"><xs:complexType><xs:sequence><xs:element name="to" type="xs:string"/><xs:element name="from" type=" xs:string"/><xs:element name="heading" type="xs:string"/><xs:element name="body" type="xs:string"/></xs:sequence></xs:complexType></xs:element>
If you want to learn XML Schema, find Schema tutorials on our home page.
To help you check the syntax of your XML files, we created an XML validator that lets you perform syntax checks on any XML file.
Please see the next chapter.