1. Documentation rules
1. Case sensitive.
2. The attribute value must be quoted (single quotes and double quotes are fine). In general, double quotes are recommended.
3. All markers must have an end symbol.
4. All empty tags must be closed.
5. There must be only one element.
6. When parsing whitespace characters, they will be output according to the actual content and will not be omitted.
7. Special character processing:
Character replacement characters
< <
> >
& &
&quto;
' '
8. Tag name convention:
a. Can contain letters, numbers, and other characters.
b. Cannot start with numbers and underscores.
c. Cannot start with characters such as xml or Xml.
d. Cannot contain spaces
2. xml statement
xml declaration standard statement: <?xml version=1.0 encoding=GB2312 standalone=yes?>
emphasize:
1. There cannot be spaces between <?xml and xml.
2.?> There can be spaces before or without them.
3. enconding and standalone are optional properties, the default encoding value is UTF-8, and the default standalone value is no.
4. Common coding methods are:
Simplified Chinese: GB2312
Traditional Chinese: BIG5
Western European characters: UTF-8, UTF-16
5.standalone indicates whether the document comes with a DTD file.
3. xml attributes
Because data can be stored in both child elements and attributes, there is no fixed rule when to use attributes and when to use sub-elements, but it is recommended that metadata should be stored in the form of attributes, and the data itself should be stored in the form of elements.
Using properties causes the following problems:
1. The attribute cannot contain multiple values (child elements can).
2. Properties are not easy to expand.
3. Attributes cannot describe structures (child elements can).
4. It is difficult to test properties through DTD.
4. Namespace
There are two ways to declare a namespace:
1. Declaration by default, all elements do not need to specify prefixes, such as:
<schema xmlns=http://www.w3.org/2001/XMLschema>
<element name=diguanianzhu type=string/>
...
</schema>
2. Explicitly declare that the xmlns keyword is associated with the prefix of the URI in a namespace, and all elements need to specify a prefix, such as:
<xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLschema>
<xsd:element name=diguanianzhu type=string/>
...
<xsd:/schema>
Emphasis: The URI used to represent the namespace is not called by the XML parser, and it does not actually access the URI, it only represents a identifier 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 format of CDATA is:
<![CDATA[character 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 ]]>.