A valid XML document can be used as a good-format document, that is, a document that complies with the XML rules, or a valid document, is a document that has been verified to comply with a DTD. A valid XML document can be used as a good-format document, that is, a document that complies with the XML rules, or a valid document, is a document that has been verified to comply with a DTD.
1. basic syntax rules
XML is case sensitive;
The start and end tags of all elements must appear in pairs and be correctly nested;
If the XML description is used, it must be the first line of the XML document:
Element attributes must be enclosed by quotation marks. single and double quotation marks are acceptable, but they must appear in pairs. For example:
XML naming rules:
The XML name starts with an underscore or letter;
XML names can contain letters, numbers, periods, underscores, and colons;
The XML name cannot contain spaces;
XML names cannot start with numbers, but can contain numbers;
The XML name is case sensitive.
Reserved markup characters, if you want to display in XML <或&之类的标记,就要使用字符的实体形式,xml中有五种预先定义了的实体: < p>
<Indicates <字符> 表示> Character & Sign & character 'indicates' character "represents" character
We can also use ENTITY to customize entities:
In this way, we can use & linux; for calling.
Spaces in the XML document content are meaningful and will be retained after conversion.
Empty element <开始并以 />End, as shown in figure
.
2. construct XML documents and valid XML documents
XML documents that comply with XML syntax rules are called structure documents. these rules are as follows:
There should be only one parent flag. the parent flag derives from all other child logos. there cannot be multiple parent logos in one document.
Nested elements should start and end in the correct order.
Child flag should be closed before the parent flag is complete.
Attribute values should be placed in double quotation marks.
A document verified by a DTD or Schema is called a valid XML document.
3. XML document composition
XML declaration:
Version defines the version number of the XML specification. Up to now, only one version number is 1.0.
Encoding: specifies the document encoding system.
Standalone, which defines whether the document is independent or whether other elements need to be loaded for correct analysis. If the XML document does not have an external entity or DTD, you can set it to no; otherwise, set it to yes. This value can be used to improve performance: if it is no, the processing speed can be improved. if it is set to yes, you must first analyze the document and determine which other files are needed before you can fully analyze the document.
Root element. Each XML document must have only one root element. The element is the first element of the document and contains all other elements. The portal in the following example is the root element, for example:
jims
...
Attribute. one or more attributes can be set for each element, for example:
Jims
Elements and attributes can both represent information. When to use elements and when to use attributes? Attribute information has limited performance. it can only represent strings. Therefore, elements should be used to flexibly represent information. Generally, the information subject is put into the element, and the attribute only contains comments or additional information.
CDATA, which uses和The data between them is displayed as the original character. the only sign that cannot appear is]>.
Annotations are very important. XML also provides the annotation function when writing programs and documents. The end of a pair of intervals is comments. Before the end of -->, the "--" and "---" cannot appear.
Processing commands, processing commands End. For example, PHP processing commands can be written, . The processing command is a tag, not an element. Therefore, like annotations, processing commands can appear anywhere outside the labels of XML documents, including before or after the root element. The most common processing command is the xml-stylesheet style sheet command, which tells the browser what style sheet is applied when the document is displayed. For example:
...
...
4. XML document tree
An XML document is a structured document that can be expressed in a tree. A tree is a simple structure composed of nodes and branches. two nodes are connected by branches. The upper node is called the parent node, and the lower node is called the child node. If a node does not have a parent node, it is called the root node of the tree. each tree must have only one root node. If a node does not have a subnode, it is called a leaf node of the tree. Only one node tree is allowed.
The preceding section describes the basic XML syntax. For more information, see other related articles in the first PHP community!