XML syntax

zhaozj2021-02-17  74

Unlike HTML, XML has a strict accordance with the syntax, and only the handler can analyze and process it only when an XML document meets the basic requirements of "format". "Good format" This standard is based on the grammatical provisions of the various logical components and physical components of the XML document, ensuring XML strict conditional, logical and good structural, which greatly improves XML application handler processing XML data. Accuracy and efficiency. In fact, the format has a good demand is the grammar requirements of the XML specification. A simple inspection method is to open the XML document you are editing with Internet Explorer4.01. If an error is reported, this document is not "well".

---- The structure of the XML document includes logical structures and physical structures.

First, logical structure

---- An XML document typically begins with an XML declaration to organize XML data through an XML element. The XML element includes tag and character data. In order to organize data more convenient, clear, you can also introduce a CDATA data block in character data, and you can introduce a comment in the document. In addition, the XML document can be included in the XML document since sometimes need to provide some instructions for the XML handler. Specifically, the role and form of each logic element is as follows:

---- 1. XML declaration

---- XML ​​declaration is one of the processing instructions, and an XML document is best begins with an XML declaration. Here is a complete XML declaration:

---- You must include a Version property in an XML processing instruction, indicating the version number of the XML used, and it must be ranked first in the attribute list. The Standalone property indicates whether the XML document is used to define DTD supporting using an external document type. The encoding property indicates the encoding standard used by the data. ----2. Elements --- element is the basic unit of XML document content. From the grammar, an element contains a starting mark, an end tag, and the data content between the tag. The form is:

Data Content

---- For markers, there is the following syntax: ---- (1) marking is essential. There is at least one element in any format in the XML document. ---- (2) Location. ---- (3) There is a correct end tag. End Mark In addition to the starting mark, you must add a slash "/" in front of the spelling and case. When there is no text content between a pair of tags, it may be not written without writing, and the final tag is confirmed by the slash "/". Such a flag is called "empty mark". ---- (4) Mark to nescery correctly. ---- (5) Tag naming should legal. The tagname should start with letters, underscore "_" or colon: "start, followed by letters, numbers, numbers". ", Colon, underscore or even characters" - ", but there is no space in the middle, and any tagname cannot be Any combination of "XML" (or "XML" case, such as "XML", "XML", "XML", etc.). ---- (6) Effective use attributes. The tag can contain any multiple properties, the attribute appears in name / value, the attribute name cannot be repeated, the name is separated by the equal sign "=" between the name and the value, and the value is caused by quotation marks. ---- 3. CDATA section ---- In tag CDATA, all tags, entity references are ignored, and the XML handler is treated as character data as a character data. The form of CDATA is as follows:

String "]]>" in the text content of CDATA, in addition, CDATA cannot nested, ---- 4. Note ---- Sometimes, people want to add some character data to the XML document and want the XML processor to do not process them. This type of text is called a comment text. In XML, the method of comment is identical to HTML, and the comment text is caused by "". There is also the following provisions for comments: ---- (1) Do not appear in the comment text "---- (2) Do not put the comment text in the mark, similarly Do not put the comment text in the entity statement or before. ---- (3) Note cannot be nested. ---- 5. Processing instruction PI ---- Processing command is used to provide information to the application of the XML document, the XML analyzer is not transmitted to the application, and the application interprets this instruction, follows it provides Information is processed. Processing instructions should follow the format below:

---- The following is an example, it is an XML document describing dictionary:

[1] [2] [3] [4] [5] XML [6] XML is an expandable meta-labeled language, it can be used to specify new set margin rules And organize data according to this rule. [7] [8] [9] [11] 001 [12] Zhang 3 [13] [14]]]> [15] [16] [17] - The logic elements that appear in this example are: ---- [1] is an XML declaration. ---- [2] is the processing instruction. ---- [3] - [17] is the individual elements in the document. In [5] line " XML "is a tag," XML "is character data. ---- [8] is a comment. ---- [9] - [14] is the CDATA section. ---- Second, physical structure ---- From physical structure, XML documents are constructed of one or more storage units, which are so-called entities. All XML documents contain a "root entity", also known as "document entities". This entity is given by the XML itself, no need to explicitly definition, it is actually the content of the entire document, which is the starting point of the XML syntax analyzer processing. In addition, other entities may also be used, these entities are identified by names, and define the definition in the file type definition DTD. ---- Simply speaking, entity acts as a role similar to alias, ie, a simple entity name can be used to represent a large text content. Like any computer alias system, entity reference simplifies the entry work, because whenever you want to use the same paragraph text, it is only necessary to use its alias, and the processor will automatically replace this alias into the corresponding text. ---- The entity is divided into two categories, as shown in the following table:

Type Universal Entity Parameter Entity Use Operation In the XML document only in the DTD in DTD in DTD, "Text Content"> External Reference Way & Entity Name;% Entity Name; The Unit Entity of Describe the unit address is defined in the following example:

---- You can use this entity as follows in the XML file:

Wang 5 (010) 6262666 & Address; ---- Entity Reference has the following rules: In addition to the predefined entities specified in the XML standard, this entity must have been declared before the XML document references an entity. Spaces cannot occur in entity references. Although other entities can be referenced in one entity, cyclic references cannot occur. The documentation of the entity must meet the requirements of the XML syntax, such as elements, tags, notes, processing instructions, entity references, and the like, and ending at another entity. ---- If entity references appear in the properties, not only, it is necessary to comply with the various rules referenced by the entities described above, but also pay attention to the following two points:

An external entity cannot be referenced in the tag properties. The character "<" cannot appear in the text, otherwise it is no longer a "well" XML file after the replacement.

Online Series Publications Computer World Microcomputer World IT Manager World Household Computer World Digital Wealth

转载请注明原文地址:https://www.9cbs.com/read-31247.html

New Post(0)