Chapter 4 XML syntax outline: 1. XML syntax rule 2. element syntax 3. syntax 4. CDATA syntax 5. namespaces syntax 6. entity syntax 7. the DTD syntax is learned in the previous three chapters. what is XML? Chapter 4 XML syntax
Outline:
I. XML syntax rules
II. element syntax
3. annotation syntax
IV. CDATA syntax
V. Namespaces syntax
6. entity syntax
VII. DTD syntax
Based on the previous three chapters, we have understood what XML is, its implementation principles, and related terms. Next, we will start to learn the XML syntax and write our own XML documents.
I. XML syntax rules
The XML document is similar to the original HTML code and uses an identifier to identify the content. The creation of XML documents must follow the following important rules:
Rule 1: XML declaration statements are required
We mentioned this in the previous chapter. Declaration is the first sentence of the XML document. its structure is as follows:
The purpose of the declaration is to tell the browser or other processing programs that this document is an XML document. The version in the declaration statement represents the version of the XML specification followed by the document; standalone performance document is accompanied by a DTD file, if any, the parameter is no; encoding represents the language encoding used by the document, the default is the UTF-8.
Rule 2: whether a DTD file exists
If the document is a 'valid XML document' (see the previous chapter), the document must have a corresponding DTD file and strictly abide by the rules set forth in the DTD file. The declaration statement of the DTD file follows the XML declaration statement in the following pattern:
Where:
'! DOCTYPE 'indicates that you want to define a DOCTYPE;
'Type-of-Doc' is the name of the document type, which is defined by you and is generally the same as the DTD file name;
The 'System/public' parameter only uses one of the two parameters. SYSTEM refers to the URL of the private DTD file of the document application, while PUBLIC refers to the URL where the document calls a public dtd file.
The 'dtd-name' is the URL and name of the dtd file. The suffix of all DTD files is '. dtd '.
We should use the following example to write it as follows:
Rule 3: pay attention to your case sensitivity
In XML documents, the case sensitivity is different.
And
Is different. Note that when writing elements, the front and back identifiers must be the same in case. Example: ajie, Written as ajieYes.
You 'd better develop a habit, either in upper case, or in lower case, or in upper case, the first letter. This reduces document errors caused by case-insensitive.
Rule 4: quote the property value
In HTML code, attribute values can be enclosed by quotation marks or not. For example, word and word can be accurately described by the browser.
However, in XML, it is stipulated that all attribute values must be enclosed by quotation marks (single quotation marks or double quotation marks). Otherwise, it will be regarded as an error.
Rule 5: All identifiers must have end identifiers.
In HTML, tags may not be displayed in pairs? Lt; br>. In XML, all identifiers must be presented in pairs. if there is a start identifier, there must be an end identifier. Otherwise, it is regarded as an error.
Rule 6: all empty identifiers must be closed.
An empty ID is an identifier with no content between the identifiers. For example
. In XML, all identifiers must have end Identifiers. for such empty identifiers, the XML processing method is to add/at the end of the original identifiers. For example:
Should be written
;
Should be written ;
Should be written