The basics of XML development: XML validation

Source: Internet
Author: User
Tags xml attribute

XML with the correct syntax is referred to as "well-formed" XML.

The XML that is validated through a DTD is "legitimate" XML.

Well-written XML document

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

A "well-formed" XML document adheres to the XML syntax rules described in the previous chapters:

The XML document must have a root element

The XML document must have a close tag

XML tags are case sensitive

XML elements must be nested correctly

XML attribute must be quoted

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<body>Don't forget the meeting this weekend!</body>
</note>

Validating an XML document

A legitimate XML document is a "well-formed" XML document that also adheres to the syntax rules of the document type definition (DTD):

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

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

XML DTD

The role of a DTD is to define the structure of an XML document. It uses a range 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)>
]>

XML Schema

The consortium supports an xml-based DTD substitute, which is named XmlSchema:

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

A generic Validator

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.