Home  >  Article  >  Backend Development  >  Sample code that explains the correct format of xml documents in detail

Sample code that explains the correct format of xml documents in detail

黄舟
黄舟Original
2017-03-30 13:41:041507browse

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&#39;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&#39;t forget me this weekend!</body>
</note>

--------------------------------------------- -------------------------------------

XML DTD
DTD definition 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 DTDs.

W3C makes DTD and Schema interchangeable. Readers can learn more in the Schema Guide.

-------------------------------------------------- ------------------------------------

Error
occurred in XML document An error will cause the XML program to stop.

The W3C XML specification states: If a program finds a valid error in processing an XML document, 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 There are different ways to decide how this HTML file should be displayed.

This never happens in XML.

The above is the detailed content of Sample code that explains the correct format of xml documents in detail. For more information, please follow other related articles on the PHP Chinese website!

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