XML Development Basics-XML Validation Code Sharing

黄舟
Release: 2017-03-25 17:11:13
Original
1555 people have browsed it

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

XML that has been verified by a certain DTD is "valid" XML.

Well-formed XML document

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

A "well-formed" XML document will comply with the XML syntax rules introduced in the previous chapters:

The XML document must have a root element

The XML document must have a closing tag

XML tags are case-sensitive

XML elements must be nested correctly

XMLAttributesMust be quoted

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don&#39;t forget the meeting this weekend!</body>
</note>
Copy after login

Validating XML documents

A valid 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>
<heading>Reminder</heading>
<body>Don&#39;t forget the meeting this weekend!</body>
</note>
Copy after login

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

XML DTD

The function of DTD is to define the structure of 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)>
]>
Copy after login

XML Schema

W3C Supports an XML-based DTD replacement called 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>
Copy after login

The above is the detailed content of XML Development Basics-XML Validation Code Sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template