XML validation

 

XML has the correct syntax is called "good form" of XML.

By validating XML DTD is "legal" XML.

Well-formed XML documents

"Good form" or "well-formed" XML document has correct syntax.

"Good form" (Well Formed) XML document will abide by the rules of XML syntax introduced in the previous chapters:

  • XML documents must have a root element
  • XML document must have a closing tag
  • XML tags are case sensitive
  • XML elements must be properly nested
  • XML attributes must be quoted
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

Validate XML documents

Legal XML document is a "good form" of XML documents, to comply with the same document type definition (DTD) syntax rules:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>  

In the above example, DOCTYPE declaration is an external DTD file references. The following paragraphs show the contents of this document.

XML DTD

A DTD is to define the structure of XML documents. It uses a series of legal elements define the structure of the document:

<!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 visit http://www.w3school.com.cn/index.html the DTD tutorial .

XML Schema

W3C supports an XML-based DTD instead of who it 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 need to learn XML Schema, please visit http://www.w3school.com.cn/index.html of XML Schema tutorial .

A generic validator

To help you check the syntax of XML documents, we created this tool so that you can check the syntax of any XML file.

See the next section.

Reproduced in: https: //www.cnblogs.com/Codenewbie/archive/2013/04/07/3003708.html

Guess you like

Origin blog.csdn.net/weixin_34302561/article/details/93448077