XML DTD
XML has the correct syntax is called "good form" in XML.
DTD validation of XML through a "legal" XML.
In the form of well-formed XML documents
"Well Formed" XML document has correct syntax.
Syntax rules described in the previous section:
- XML document must have a root element
- XML elements must have a closing tag
- XML tags are case sensitive
- XML elements must be properly nested
- XML attribute values must be quoted
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Validate XML documents
Legal XML document is a "Well Formed" XML document, which is consistent with the Document Type Definition (DTD) rules:
<!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 example above, DOCTYPE declaration is a reference to an external DTD file. The following paragraphs show the contents of the file.
XML DTD
DTD is intended to define the structure of XML documents. It uses a series of legal elements to define the document structure:
[
<!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 on our home page to find DTD tutorial.
XML Schema
W3C supports an XML-based DTD instead of who it called XML Schema:
<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, please our home page to find Schema tutorial.
A generic XML Validator
To help you check the syntax of the XML file, we have created an XML validator, so you can check syntax for any XML document.
See the next chapter.