Detailed explanation of XML syntax

Detailed explanation of XML syntax
1. Documentation Rules

1. Case sensitive.

2. The attribute value must be enclosed in quotes (either single quotes or double quotes). In general, double quotes are recommended.

3. All tags must have an end symbol.

4. All empty tags must be closed.

5. There must be one and only one element.

6. When parsing blank characters, the actual content will be output without abbreviation.

7. Special character processing:
Character replacement character
< &lt;
> >
& &amp;
" &quto;
' &apos;

8. Tag name conventions:
a.Can contain letters, numbers, and other characters.
b. It cannot start with a number or an underscore.
c. It cannot start with characters such as xml or Xml.
d. Cannot contain spaces


2. XML declaration

XML declaration standard statement: <?xml version="1.0" encoding="GB2312" standalone="yes"?>
emphasize:
1. There should be no space between "<?" and "xml" in "<?xml".
2. There can be a space before "?>" or not.
3. encoding and standalone are optional attributes. The default value of encoding is "UTF-8" and the default value of standalone is "no".
4. Common encoding methods are:
Simplified Chinese: GB2312
Traditional Chinese: BIG5
Western European characters: UTF-8,UTF-16
5.standalone indicates whether the document is accompanied by a DTD file.

3. XML attributes

Because data can be stored in both sub-elements and attributes, there is no fixed rule as to when to use attributes and when to use sub-elements, but it is recommended that metadata should be stored as attributes, while the data itself should be stored as elements.
Using attributes raises the following questions:
1. Attributes cannot contain multiple values ​​(sub-elements can).
2. Attributes are not easy to expand.
3. Attributes cannot describe structure (sub-elements can).
4. Attributes are difficult to test via DTD.

4. Namespace

There are two ways to declare a namespace:
1. By default, 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. Clearly declare that the xmlns keyword is associated with a namespace URI prefix, and 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>
Emphasize: The URI used to represent the namespace is not called by the XML parser, and the URI is not actually accessed. It just represents an identification name.

5. XML-specific tags: CDATA

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

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

<<:  Web Design Tutorial (4): About Materials and Expressions

>>:  CSS solution for centering elements with variable width and height

Recommend

How to insert weather forecast into your website

We hope to insert the weather forecast into the w...

Axios project with 77.9K GitHub repository: What are the things worth learning?

Table of contents Preface 1. Introduction to Axio...

Linux/Mac MySQL forgotten password command line method to change the password

All prerequisites require root permissions 1. End...

Vue encapsulates the public function method of exporting Excel data

vue+element UI encapsulates a public function to ...

Markup language - web application CSS style

Click here to return to the 123WORDPRESS.COM HTML ...

Teach you how to deploy zabbix service on saltstack

Table of contents Saltstack deploys zabbix servic...

Problems encountered when updating the auto-increment primary key id in Mysql

Table of contents Why update the auto-increment i...

How to use Vue cache function

Table of contents Cache function in vue2 Transfor...

Common rule priority issues of Nginx location

Table of contents 1. Location / Matching 2. Locat...

Tutorial on installing MySQL with Docker and implementing remote connection

Pull the image docker pull mysql View the complet...

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being a...