XML entity reference, comment, naming rules

Source: Internet
Author: User
Checkout corresponds to checkin, and export corresponds to import. In XML, some characters in checkout have special meanings. If you place the & quot; & lt; & quot; character in the XML element, an error occurs because the parser starts to treat it as a new element. XML errors will occur:

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, useEntity referenceTo replace the "<" character:

 
  if salary < 1000 then
 

In XML, there are 5 predefined entity references:

< < Less
> > Greater
& & And number
' ' Single quotes
" " Quotation marks

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 retained

HTML truncates (Merges) multiple consecutive space characters into one:

HTML: Hello my name is David. output: Hello my name is David.

In XML, spaces in the document are not deleted.

XML naming rules

XML elements must follow the following naming rules:

  • The name can contain letters, numbers, and other characters.

  • The name cannot start with a number or punctuation.

  • The name cannot start with the character "xml" (or XML or Xml ).

  • The name cannot contain spaces.

You can use any name without reserved words.

Best naming convention

Make the name descriptive. The underlined name is also good.

The name should be brief, for example: Instead: .

Avoid "-" characters. If you name it in this way: "first-name", some software will think that you need to extract the first word.

Avoid "." characters. If you name "first. name" in this way, some software considers "name" as the attribute of the object "first.

Avoid ":" characters. The colon is converted to a namespace (described later ).

XML documents often have a corresponding database, where fields correspond to elements in XML documents. There is a practical experience, that is, using database naming rules to name elements in XML documents.

Non-English letters such as équáá are also legal XML element names, but you need to pay attention to problems that may occur when software developers do not support these characters.

The above is the content of XML entity reference, comments, and naming rules. For more information, see PHP Chinese website (www.php1.cn )!

Related Article

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.