XML technical m...login
XML technical manual
author:php.cn  update time:2022-04-14 15:57:53

XML validation



XML with correct syntax is called "well-formed" XML.

XML that passes DTD validation is "legal" XML.


Well-formed XML document

A "well-formed" XML document has correct syntax.

The syntax rules described in the previous chapters:

  • The XML document must have a root element

  • XML elements must There is a closing tag

  • XML tags are case-sensitive

  • XML elements must be properly nested

  • XML attribute values ​​must be quoted

<?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>


Validate XML document

A valid XML document is "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>

On top In the case of , the DOCTYPE declaration is a reference to an external DTD file. The following paragraphs show the contents of this file.


XML DTD

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, find DTD tutorials on our homepage.


XML Schema

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, please contact us Find Schema tutorials on the home page.


A universal XML validator

To help you check the syntax of XML files, we have created XML Validator so that you can perform syntax checks on any XML file.

Please read the next chapter.


php.cn