1. All XML elements must have closing tags
In HTML, you often see elements without closing tags:
<p>This is a paragraph <p>This is another paragraph
In XML, It is illegal to omit the closing tag. All elements must have closing tags:
<p>This is a paragraph </p> <p>This is another paragraph </p>
2. XML tags are case-sensitive
XML elements are defined using XML tags.
XML tags are case-sensitive. In XML, the tag
Opening and closing tags must be written using the same case.
3. XML must be nested correctly
In HTML, you often see elements that are not nested correctly.
<b><i>This text is bold and italic</b></i>
In XML, all elements must be correctly nested within each other:
<b><i>This text is bold and italic</i></b>
Correct nesting means: since the element is opened within the element , then it must be closed within the element.
4. The XML document must have a root element
The XML document must have one element that is the parent element of all other elements. This element is called the root element.
<root> <child> <subchild>....</subchild> </child> </root>
5. XML attribute values must be quoted
<note date="08/08/2008"> </note>
Note: Only "" is legal, but it's a good practice to use an entity reference instead.
6. In XML, spaces will be preserved.
7. XML stores line breaks in LF
In window applications, line breaks are usually stored as one character: carriage return (CR) and Line feed (LF). This pair of characters has similarities to the action of a typewriter setting a new line. In Unix applications, new lines are stored as LF characters. Macintosh applications use CR to store new lines.
8. Summary:
All XML elements must have closing tags, opening tags and closing tags must be written in the same case, and must be nested correctly , there must be a root element, XML attribute values must be quoted, etc. The syntax rules of XML are simple and logical. These rules are easy to learn and easy to use.
If you want to learn more related content, please visit the PHP Chinese website: XML video tutorial
The above is the detailed content of An article takes you into XML syntax rules. For more information, please follow other related articles on the PHP Chinese website!