Basic XML development-detailed description of XML syntax rules

Source: Internet
Author: User
Tags xml attribute
XML syntax rules are simple and logical. These rules are easy to learn and use. All XML elements must have tags closed in HTML. it is often seen that elements without tags closed: XML syntax rules are simple and logical. These rules are easy to learn and use.

All XML elements must have close labels

In HTML, you will often see elements that do not close tags:

This is a paragraph

This is another paragraph

In XML, it is invalid to omit and close tags. All elements must have a close tag:

This is a paragraph

This is another paragraph

Note: You may have noticed that the XML declaration does not close the tag. This is not an error. Declarations are not part of XML. It is not an XML element and does not need to close tags.

XML tags are case sensitive.

XML elements are defined using XML tags.

XML tags are case sensitive. In XML, tags And labels Is different.

You must use the same case to write the enable and disable tags:

 
  
This is incorrect.
 
 
  
It is formal and correct.
 

Note: open and close tags are usually called start and end tags. No matter which term you like, they share the same concept.

XML must be correctly nested

In HTML, you will often see elements that are not correctly nested:

This text is bold and italic

In XML, all elements must be correctly nested with each other:

This text is bold and italic

In the preceding example, correct nesting means:The element is inElement, it must beElement.

XML documents must have root elements

An XML document must have one element that is the parent element of all other elements. This element is called the root element.

    .....   

The XML property value must be enclosed in quotation marks.

Similar to HTML, XML can also have attributes (name/value pairs ).

In XML, XML attribute values must be enclosed by quotation marks. Study the following two XML documents. The first is incorrect, and the second is correct:

   George   John     George   John  

Entity reference

In XML, some characters have special meanings.

If you put the character "<" in an XML element, an error occurs because the parser starts to treat it as a new element.

XML errors will occur:

  if salary < 1000 then 

To avoid this error, use an entity reference instead of the "<" character:

  if salary < 1000 then 

In XML, there are 5 predefined entity references:

Note: in XML, only the characters "<" and "&" are indeed invalid. It is a good habit to replace it with entity references.

Annotations in XML

The syntax for writing comments in XML is similar to that in HTML:

 In XML, spaces are reserved. HTML splits multiple consecutive space characters into one: HTML: Hello my name is Tove.

Output: Hello my name is Tove.

In XML, spaces in the document are not deleted.

Line Feed with LF storage in XML

In Windows applications, line breaks are usually stored as a pair of characters: carriage returns (CR) and line breaks (LF ). This character is similar to the setting of a new line on the typewriter. In Unix applications, new lines are stored as LF characters. The Macintosh application uses CR to store new rows.

The above is the detailed description of XML syntax rules. For more information, see other related articles in the first PHP community!

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.