May 27, 2021 XML
XML with the correct syntax is called "good form" XML.
XML validated by DTD is "legitimate" XML.
"In good form" XML documents have the correct syntax.
Grammar rules described in the previous section:
<?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>
Legitimate XML documents are "in good form" XML documents, which also conform to the rules of 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 example above, the DOCTYPE declaration is a reference to an external DTD file. The following paragraph shows the contents of this file.
The purpose of DTD is to define the structure of XML documents. It uses a series of legitimate 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 the DTD tutorial on our home page.
W3C supports an XML-based DTD replacement 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 the Schema tutorial on our home page.
To help you check the syntax of XML files, we created an XML validator so that you can syntax check any XML file.
Take a look at the next chapter.