XML syntax rules are simple and strict, so they are easy to learn and use. Because of this, it is relatively easy to write software for reading and operating XML. XML syntax rules are simple and strict, so they are easy to learn and use.
Because of this, it is relatively easy to write software for reading and operating XML.
--------------------------------------------------------------------------------
Example of an XML document
XML documents use self-described and simple syntax.
Lin
Ordm
Reminder
Don't forget me this weekend!
Line 2 of the document: XML declaration-defines the XML Standard version that this document complies with. In this example, it is the standard of version 1st, the ISO-8859-1 (Latin-1/West European) character set is used.
The first line of the document is the root element (like saying "this document is a note "):
Line 3-6 of the document describes the four subnodes (to, from, heading, and body) of the root element ):
Lin
Ordm
Reminder
Don't forget me this weekend!
The last line of the document is the end of the root element:
Can you see from this document that this is a note left by Ordm for Lin? Can we not admit that XML is a beautiful self-describing language?
--------------------------------------------------------------------------------
All XML documents must have an end mark.
In XML documents, the Ignore end tag does not comply with the rules.
In HTML documents, some elements can be unending tags. The following code is completely legal in HTML:
This is a paragraph
This is another paragraph
However, the end mark must be included in the XML document, as shown in the following example:
This is a paragraph
This is another paragraph
Note: You may have noticed that the first line in the above example does not end with the mark. This is not an error. Because the XML declaration is not part of the XML document, it is not an XML element and should not have an end mark.
--------------------------------------------------------------------------------
XML tags are case sensitive.
Unlike HTML, XML tags are case sensitive.
In XML, Mark And Mark Are two different tags.
Therefore, the start and end tags must be in the same case in the XML document.
This is incorrect
// Incorrect
This is correct
// Correct
--------------------------------------------------------------------------------
All XML elements must be reasonably included
Improper nested inclusion is not allowed in XML.
In HTML, some improper inclusion is allowed. for example, the following code can be parsed by the browser:
This text is bold and italic
In XML, all elements must be correctly nested. the above code should be written as follows:
This text is bold and italic
--------------------------------------------------------------------------------
All XML documents must have a root element.
The first element in the XML document is the root element.
All XML documents must contain a separate tag, and all other elements must be nested in the root element. XML documents have only one root element.
All elements can have child elements. child elements must be correctly nested in the parent element. the following code can be illustrated as follows:
.....
--------------------------------------------------------------------------------
The attribute value must be enclosed in quotation marks ""
In XML, the attribute values of an element are not enclosed by quotation marks.
Like HTML, XML elements can also have attributes. XML element attributes are paired with names/values. The XML syntax specification requires that the XML element attribute values be enclosed in quotation marks. Please refer to the two examples below. The first is incorrect, and the second is correct.
Lin
Ordm
Reminder
Don't forget me this weekend!
Tove
Jani
Reminder
Don't forget me this weekend!
The error in the first document is that the attribute value is not quoted in quotation marks.
The correct syntax is: date = "12/11/99". incorrect syntax: date = 12/11/99.
--------------------------------------------------------------------------------
When XML is used, white space is retained
In XML documents, the blank part is not automatically deleted by the parser.
This is different from HTML. In HTML, such a sentence:
"Hello my name is Ordm"
Will be displayed:
“Hello my name is Ordm”,
Because the HTML parser automatically removes the blank part of the sentence.
--------------------------------------------------------------------------------
Using XML, CR/LF is converted to LF
When XML is used, new rows are always identified as LF (Line Feed, Line Feed ).
The preceding section describes the usage and learning of xml syntax in detail. For more information, see other related articles in the first PHP community!