A detailed explanation of XML syntax

Source: Internet
Author: User
Tags cdata tag name xml parser xmlns

First, document rules

1. Case sensitive.

2. Attribute values must be enclosed in quotation marks (both single and double quotes) and are generally recommended for use with double quotes.

3. All tokens must have a closing symbol.

4. All empty tags must be closed.

5. Must have and only one element.

6. When parsing white space characters, it will be output according to the actual content, not abbreviated.

7. Special character Processing:
Character substitution character
< &lt;
> &gt;
& &amp;
"&quto;
' &apos;

8. Tag Name Convention:
A. Can contain letters, numbers, and other characters.
B. Cannot begin with numbers and underscores.
C. You cannot start with a character such as XML or XML.
D. Cannot contain spaces


Second, the XML declaration

XML declaration standard statement: <?xml version= "1.0" encoding= "GB2312" standalone= "yes"?>
Emphasize:
1. "<?xml" in "the" and "XML" cannot have spaces in between.
2. "?>" can be preceded by a space, or it may not be.
3.enconding and standalone are optional properties, encoding default is "UTF-8" and standalone default is "no".
4. Common coding methods are:
Simplified Chinese: GB2312
Traditional Chinese: BIG5
Western European character: Utf-8,utf-16
5.standalone Indicates whether the document comes with a DTD file.

Three, XML attributes

Because data can be stored either in child elements or in attributes, when attributes are used, when child elements are used, there is no fixed rule, but it is suggested that metadata should be stored as attributes and that the data itself should be stored as elements.
Using attributes raises the following issues:
1. Attributes cannot contain multiple values (child elements can).
2. Properties are not easy to expand.
3. Properties cannot describe structs (child elements can).
4. Attributes are difficult to test with DTDs.

Four, the name space

Declaring namespaces two ways:
1. Default declaration, all elements do not need to specify a prefix, such as:
<schema xmlns= "Http://www.w3.org/2001/XMLschema" >
<element name= "Diguonianzhu" type= "string"/>
......
</schema>
2. Explicitly declares that the xmlns keyword is associated with the prefix of a namespace's URI, and that all elements need to specify a prefix, such as:
<xsd:schema xmlns:xsd= "Http://www.w3.org/2001/XMLschema" >
<xsd:element name= "Diguonianzhu" type= "string"/>
......
<xsd:/schema>
Emphasis: The URI used to represent the namespace is not invoked by the XML parser and does not actually access the URI, it simply represents an identity name.

V. XML-specific Tags: CDATA

CDATA The full name is character data, which is mainly used to display special characters, such as "<".
CDATA The syntax format is:
<! [cdata[the character to be displayed]]> as:
<?xml version= "1.0"?>
<data>
<! [cdata[
<ok alma!> by a&b!

]]>
</data>
Emphasis: CDATA cannot be nested; the character to display cannot contain "]]>".

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.