XML easy learning Manual (5) XML syntax 2

Source: Internet
Author: User
Chapter 4 XML syntax II. element syntax elements consist of a pair of identifiers and their content. Like this: ajie. The element name is the same as the identifier name. The identifier can be further described by attributes. In XML, there are no reserved words. The fourth chapter is the XML syntax.

II. element syntax

An element consists of a pair of identifiers and the content. Like this: ajie. The element name is the same as the identifier name. The identifier can be further described by attributes.

In XML, there are no reserved words, so you can use any words as the element name. However, the following specifications must also be observed:

1. the name can contain letters, numbers, and other letters;

2. the name cannot start with a number or;

3. the name cannot start with the letter xml (or XML or Xml ...).

4. the name cannot contain spaces.

5. the name cannot contain ':' (colon)

In order to make elements easier to read and control, we also have some suggestions:

1. do not use '.' in the name '.'. In many programming languages, '.' is an object attribute, such as font. color. For the same reason, '-' is not recommended. it must be used instead;

2. the name should be as short as possible.

3. the name should be case-insensitive to the same scale.

4. the name can contain non-English characters, such as Chinese characters. But some software may not support it. (IE5 currently supports Chinese elements .)

In addition, I would like to add some clarification on attributes. In HTML, attributes can be used to define the display pattern of elements. for example, word will display word in red. In XML, attributes only describe the identifiers and are irrelevant to the display of element content. For example, the word is not displayed in red. (So some netizens will ask: how can I display the text in red in XML? This requires the application of CSS or XSL, which will be described below .)

3. annotation syntax

Annotations are added to the XML document to facilitate browsing and understanding. the additional information added to the XML document will not be described by the program or displayed by the browser.

The syntax of the annotation is as follows:



As you can see, it is the same as the annotation syntax in HTML and is very easy. Developing a good habit of commenting will make your documents easier to protect, share, and look more professional.

IV. CDATA syntax

CDATA stands for character data, which is translated as character data. When writing an XML document, we sometimes need to display letters, numbers, and other symbols, such as '<'. in XML, these characters have special meanings, what should we do? This requires the CDATA syntax. The syntax format is as follows:

这里放置需要显示的字符

For example:

ajie</AUTHOR>

The content displayed on the page will be 'ajie'


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.