The composition of the XML document
An XML document consists of two parts: the first part is the preface to the document, and the second part is the document Element (node).
1. Documentation Preamble
The document prologue is usually at the top of the XML document and appears before the root element, which is a specific section that contains the XML document settings information. The preamble to the XML document consists of the following sections:
- XML declaration: Used to set the basic parameters required for parsing XML documents.
- Processing instructions: A special directive is fed back to a particular type of software.
- Document type definition: Used to set up more advanced information, such as entities, attributes, and validity-related information.
- Note: Used to alert an XML document author or to temporarily highlight an imperfect part of a document.
2. Document elements
XML document elements form a tree structure, so document elements are also referred to as root elements. The root element contains all the other elements and data content of the document.
Declaration of an XML document
An XML document declaration is a small collection of configuration information that provides relevant information when the XML parser is being processed for documentation. Each XML document should contain an XML declaration, and the XML declaration must be placed on the first line of the document. The syntax format for the XML declaration is as follows:
<?xml Property 1 Property 2 ...? >
The XML declaration includes three attributes, each of which is set to the exact form: Property name = "Property value". Where property values need to be enclosed in double or single quotation marks, separated by spaces between multiple attributes. The names of the three attributes in the XML declaration are: version, encoding, and standalone.
1.version
The Version property is used to declare the XML standard version that the XML document follows. The value of this property is now typically 1.0, although XML 1.1 is already referred to as the recommended standard for the big picture, but most XML parsers use the XML 1.0 standard. Version is a property that must be included in an XML declaration.
2.encoding
The encoding property is used to tell the XML parser what character encoding to use for the current XML document. This property is optional. When a character encoding is not explicitly given in the XML declaration, the XML parser defaults to the XML document using the UTF-8 character encoding.
3.standalone
The standalone property defines whether the document can be processed without reading any other files. For example, if the XML document does not reference any other files, you can specify that the property value is yes. If the XML document references other files that describe what the document can contain, you can specify that the property value is No. Because no is the default property value for the standalone property, fewer standalone properties are seen in the XML declaration.
Note that if both the encoding and standalone properties are set, the standalone property must be located after the encoding attribute.
Processing directives for XML documents
The processing instruction for XML is referred to as pi (processing instruction), which is used to provide the XML parser with information that is passed to an application or script, or to use processing instructions to specify how the application processes or displays the document. The declaration statement at the beginning of the XML document is a special case of processing instructions.
Processing directives generally have the following syntax format:
<? Target Program name Directive?>
"Target program name" means the name of the processing software or script that the instruction is directed to, and it is important to note that the names of the uppercase or lowercase letters, such as XML, XSL, etc., are reserved and can no longer be used as the names of other processing software or script programs; > "Any contiguous character other than the character.
Special processing instructions that can be used in XML documents are determined by the parser of the document. If you use IE as an XML parser, you can use standard processing instructions for how high-speed Internet Explorer handles or displays documents.
For example, the following code specifies a reference to a CSS style sheet:
<?xml-stylesheet type= "Text/css" href= "Mystyle.css" ?>
The first item in the processing instruction is a name, called the target of the directive. The name above is "Xml-stylesheet". Names beginning with XML are reserved for XML-only processing names. The following instruction tells IE to use Mystyle.css's cascading style sheet to display the document.
You can add processing instructions anywhere in the XML document, place processing instructions in the preamble of the document, or place them in the contents of the element. In addition, processing instructions can be placed in the document type definition (DTD) when needed, as long as the processing instruction is not placed in the markup of the DTD document.
Reference:
"XML Practical Tutorial" Chen, Su Jing, Wang Long and other authoring
Structure of the XML document