XML Guide-XML syntax

Source: Internet
Author: User
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 as "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 ).
Do you know what a typewriter is? The typewriter was a specialized typing machine used in the last century. ^ & ^
After you have typed a line with a typewriter, you usually have to move the typing head to the left of the paper.
In Windows applications, new lines in text are often identified as cr lf (carriage return, line feed, carriage return, and line feed ). In Unix applications, the new line is often identified as LF. Some applications only use CR to represent a new line.

Annotations in XML
The syntax for comment in XML is basically the same as that in HTML.


XML is nothing special.
XML is really nothing special. It's just plain text that is expanded with angle brackets.
You can also edit XML documents by editing common text.
However, in an application that supports XML, XML tags often correspond to special operations. some tags may be visible, while some tags may not be displayed, there is no special operation.

The preceding section describes the XML syntax in the XML Guide. For more information, see The PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.