XML syntax rules are simple and very logical. These rules are easy to learn, and very easy to use.
All XML elements must have a closing tag
In HTML, some elements do not have a closing tag:
In XML, omit closing tag is illegal. All elementsmust have a closing tag:
Note: From the above examples, you might have noticed that the XML declaration did not close the tab.This is not an error. Declaration is not part of the XML document itself, it has no closing tag.
XML tags are case sensitive
XML tags are case sensitive. Tag <Letter> tag <letter> is different.
You must use the same case to write open and closing tags:
<message>This is correct</message>
Note: Opening and closing tags are commonly referred to as the start and end tags.Whether you like what terms, their concepts are the same.
XML must be properly nested
In HTML, you often see are not properly nested elements:
In XML, all elementsmust be properly nested within each other:
In the example above, the correct meaning is nested: Because <i> element within <b> element to open, then it must be closed in the <b> element.
XML document must have a root element
XML document must have aelement is the parentof all other elements. This elementis called the root element.
XML attribute values must be quoted
Similar to HTML, XML elements can have attributes in (name / value pairs).
In XML, XML attribute values must be quoted.
Please study the following two XML documents. The first one is incorrect, the second is correct:
Error in the first document is, note the date property element is not quoted.
In XML, some characters have special significance.
If you put the character "<" on the XML element, an error occurs because the parser will use it as the beginning of a new element.
This will generate an XML error:
To avoid this error, please useentity references instead of "<" character:
In XML, there are 5 predefined entity references:
Note: In XML, only the characters "<" and "&" is indeed illegal.Greater than sign is legal, but using entity references instead it is a good habit.
XML comments in
Write a comment in XML syntax and HTML syntax is very similar.
<-! This is a comment ->
In XML, the space will be reserved
HTML will cut more than one consecutive space characters (merged) into one:
In XML, a document spaces will not be deleted.
XML is stored in LF line feed
In Windows applications, a new line is usually used to store a pair of characters: carriage return (CR) and line feed (LF).
In Unix and Mac OSX, use LF to store a new line.
In the old Mac system, use CR to store the new row.
XML is stored in LF line feed.