Chapter 4 XML Syntax Outline: One. Xml Syntax Rules II. The grammatical three of the elements. The syntax of the symbol. The syntax of the syntax. What is already XML, its implementation principle, and related terms. Next, we start learning XML's grammatical specification and write your own XML document. I. xml syntax rule XML document and HTML's original code is similar, and it is also identified by identity. Creating an XML document must follow the following important rules: Rules 1: There must be an XML declaration statement that we have already mentioned when he learned in the next chapter. The statement is the first sentence of the XML document, its format is as follows: XML Version = "1.0" Standalone = "YES / no" encoding = "UTF-8"?> The role is to tell your browser or other handler: this The document is an XML document. The Version in the statement represents the version of the XML specification of the document. Standalone indicates whether the document comes with a DTD file. If there is, the parameter is NO; Encoding indicates the language encoding used by the document. The default is UTF-8. Rule 2: Is there a DTD file If the document is a "valid XML document" (see the last chapter), the document must have the corresponding DTD file and strictly abide by the DTD file formulation. The DTD file declaration statement is followed behind the XML declaration statement, the format is as follows: where: "! Doctype" means you want to define a doctype; "Type- Of-doc "is the name of the document type, which is defined by yourself, usually the same DTD file name;" System / public "These two parameters use only one. System is the URL of the private DTD file used by the document, and the public refers to the URL of a public DTD file. "DTD-Name" is the URL and name of the DTD file. All DTD files are named ".dtd". We still use the above examples, should be written as this: XML Version = "1.0" Standalone = "no" encode = "UTF-8"?> rule 3: Note your Size in XML documentation, case is different.
and
are different logos. Note that when you write an element, you should keep the size before and after. For example:
Rule 5: All identities must have the corresponding end identity in HTML, the identifier may not be pair, ratio, lt; br>. In XML, all identities must be paired, there is a starting identifier, and must have an end identity. Otherwise it will be considered an error. Rules 6: All empty probes must also be closed to the identification of the identity between the identification pair. For example,
, , etc. In XML, it is specified that all identities must have an end identity. For such empty probability, the method processed in XML is that the original identity is finally added /, it is OK. For example:
should be written as
; should be written as ; should be written as
Chapter 4 XML Syntax II. The syntax elements of the element are composed of a pair of identifications and the content therein. Just like this: Ajie. The name of the element and the name of the identity are the same. Identification can be further described with attributes. In XML, there is no reserved word, so you can use any words as the element name as you want. However, you must also comply with the following specification: 1. You can include letters, numbers, and other letters in the name; 2. Name cannot start with a number or "_" (underscore); 3. Name cannot be in letter XML (or XML or XML ..) At the beginning 4. The name cannot contain spaces 5. The middle cannot contain ":": (colon) in the middle of the ":" (colon) to make the element easier to read understanding and operation, we have some suggestions: 1. Do not use "." Because in many program languages, "." Is an object of the object, for example: font.color. The same reason "-" is also best not to use, must be used, instead of "_"; 2. The name is as short as possible. 3. The case is used to use the same standard. 4. Names can use non-English characters, such as Chinese. But some software may not be supported. (IE5 is currently supporting Chinese elements.) In addition, add a description of the property. In HTML, the property can be used to define the display format of the element, such as Word font> will display Word as red. In XML, the attribute is only a description of the identity, and is independent of the display of the element content. For example, the same sentence: Word font> does not display Word as red. (So, some netizen will ask: How to display the text as red in XML? This requires CSS or XSL, we will tell it in detail below.) Third. The syntax of the comment is to facilitate reading and understanding, in XML documentation Added additional information will not be interpreted by the program or the browser is displayed. The syntax of the comment is as follows: It can be seen that it is the same as the comment syntax in HTML, it is very easy. Develop good annotations habits will make your document more convenient for maintenance, sharing, and look more professional. Four. CDATA's grammatical CDATA full name Character Data, translated as character data. When we write an XML document, sometimes you need to display letters, numbers, and other symbols itself, such as "<", and in XML, these characters already have special meanings, what should we do? This requires the CDATA syntax. The syntax format is as follows: For example: ajie author>]]> The content displayed on the page will be "
Chapter 4 XML Grammar 5. The syntax of namespaces namespaces translated into a name space. What is the role of name space? This contradiction occurs when we use others or multiple DTD files in an XML document: This may cause data confusion. For example, in a document