XML's grammar rules are simple and strict, very easy to learn and use.
Because of this, software written and operates XML is also relatively easy.
An example of an XML document
The XML document uses the self-description and simple syntax.
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note>
Documentation Line 1: XML Declaration - Defines the version of the XML standard following this document, in this example is the standard of version 1.0, use ISO-8859-1 (Latin-1 / West European "character set.
The second line of the document is the root element (like this document is a note "):
Documentation 3-6 describes four child nodes of the root element (to, from, heading, and body):
The last line of the document is the end of the root element:
Note>
Can you see this document? Is this a note for LIN? Can you recognize that XML is a beautiful self-description language?
All XML documents must have an end tag
In the XML document, ignore the end tag is not compliant.
In the HTML document, some elements can be no end tags. The following code is completely legal in HTML:
this is a paragraph
this is another paragraph
But in the XML document, there must be an end tag, like the following example:
this is a paragraph p>
this is another paragraph p>
Note: You may have noticed that the first line in the above example does not end the mark. This is not an error. Because the XML declaration is not part of the XML document, he is not an XML element, and there should not be an end tag.
XML tags are sensitive
This is different from HTML, XML tag is sensitive.
In XML, tag
Therefore, the case where the labeling and end tags starting in the XML document must remain consistent.
All XML elements must be reasonably included
Incorrect nested included in XML is not allowed.
In HTML, there are some incorrect included, such as the following code can be parsed by browser:
this text is bold and italic b> i>
All elements in XML must be correctly nested, the above code should be written:
this text is bold and italic i> b> 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 to define that all other elements must be nest in the root element. The XML document has only one root element.
All elements can have sub-elements, the child element must be correctly nested in the parent element, the following code can be imaged:
child>
root>
Attribute value must use quotation marks ""
In XML, the attribute value of the element does not meet the quotation marks.
Like HTML, XML elements can also have attributes. The properties of the XML element are in the appearance of name / value. XML syntax specification requires XML element attribute values to be drawn by quotation marks. Please see the two examples below, the first is wrong, the second is correct.
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note>
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note>
The error of the first document is that the attribute value is not intended to be induced.
The correct way is: DATE = "12/11/99". Incorrect Writings: Date = 12/11/99.
Use XML, blank will be retained
In the XML document, the blank portion will not be 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 parts in the sentence.
Use XML, CR / LF is converted to LF
Using XML, the new row is always identified as LF (Line Feed, wrap).
Do you know what the typewriter is it? Oh, the typewriter is a special typing machine used in the last century. ^ & ^
When you use a type of type, you usually have to move the word head to the left side of the paper.
In a Windows application, new lines in text are usually identified as Cr Lf (Carriage Return, Line Feed, Enter, Return). In UNIX applications, the new line is usually identified as LF. There are also applications to use CR to represent a new line.
Note in XML
The syntax of the comments in XML is basically the same as the HTML.
XML is nothing special, XML does not have any special place. He is just some ordinary plain text with a sharp bracket.
Editing a common text can also edit an XML document.
However, in a support for XML, XML tags often correspond to special operations, and some markers may be visible, and some markers may not be displayed without any special operations.