Home > Article > Backend Development > XML Guide - XML Validation
An XML document that conforms to the grammar is called a well-structured XML document.
An XML document that passes DTD validation is called a valid XML document.
"Well-structured" XML document
A well-structured XML document should use correct syntax.
A well-structured XML document should comply with XML syntax rules. The example given in the previous chapter is a well-structured XML document:
<?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>
"Valid" XML document
A valid XML document should comply with the description of the DTD.
A valid XML document is also a well-structured XML document and must also comply with the rules of the DTD.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE note SYSTEM "InternalNote.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
XML DTD
DTD defines the legal elements available in XML documents.
The purpose of DTD is to define the legal building blocks of XML documents. He determines the internal structure of the XML document by defining a series of legal elements. A well-structured XML document is not necessarily a valid XML document, but a valid XML document must be a well-structured XML document. If you want to learn more about DTD, you can refer to the DTD Guide.
XML Schema
XML Schema (XML Schema) is a replacement for XML-based DTD.
W3C makes DTD and Schema interchangeable. Readers can learn more in the Schema Guide.
Error
An error that occurs in the XML document will cause the XML program to stop.
The W3C XML specification states: If a program finds a valid error in processing an XML document, then the program SHOULD terminate. This is why XML software is relatively easy to write. All XML documents should be consistent.
In HTML, HTML files may contain many errors (for example, an element has a start tag but no end tag). This is also one of the reasons why HTML browsers are so large. When they find errors, they have different method to determine how this HTML file should be displayed.
This never happens in XML.
The above is the content of the XML Guide-XML Confirmation. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!