XML document structure
1. XML document structure
XMLDocumentIs composed of a group of entities identified by unique names. It is also composed of data and description data tags.
The document consists of declaration, element, comment, character reference, and processing commands.
2. Create an XML document
XML declaration is always the first line of any XML document.
1. Statement XML declaration:Match the appropriate Parser for the XML document.
XML declaration Syntax:
<? XML version = "XML version" standalone = "No or yes" encoding = "UTF-8 or UTF-16 or gb2321 or GBK"?>
<? And?> : Start and end of the table Processing Command;
Version: XML version. The default value is 1.0;
Standalone: whether to use external declarations;
Encoding: character encoding;
2. Create the root element:There is only one function for describing a document.
Syntax:
<? XML version = "1.0"?>
<Root element name>
Root Element Content
</Root element name>
3. Create XML Code: Create custom elements (elements) and attributes (attributes ).
1. elements are the basic unit of XML content, including tags and content.
2. All XML elements must reasonably contain nesting.
3. XML tags are case sensitive.
4. Three Meanings can be specified for a tag: schema, semantic, or style.
Structure specifies the relationship between different elements in the document;
Semantics associates a single element with the real world outside the document;
Style specifies how an element is realistic;
5. the attribute value must be enclosed in quotation marks ""
Syntax:
<Tag Name property name = "property value">
Data
</Tag Name>
3. annotations in XML
Syntax:
<! -- This is a comment -->
1. The comment text should not contain "-".
2. It cannot be used in a tag and can be used in a tag set.
3. It cannot be placed in the object declaration or before the XML declaration.
4. Handle the mission
Provide a piece of information for applications that use this XML document.
Format:
<? XML: Application name command information?>
The location is between the XML Declaration and the root element.
When attaching a style sheet to an XML document, you must provide a processing command:
<? XML version = "1.0" endcoding = "gb2321"?>
<? XML: stylesheet type = "text/XSL" href = "top.css"?>
<Root element> data </root element>
5. character data classification between tags
1. pcdata
Resolved character data.
2, CDATA
Indicates the text that is not parsed by parsing. It is easy to contain special characters.
Format:
<Root element>
<! [CDATA [
<Mark 1>
<Sub-mark 1 >#$ % special character </sub-mark 1>
<Sub-mark 2> $ % ^ special character </sub-mark 2>
.....
</Mark 1>
]>
<Mark 2>
....
</Mark 2>
</Root element>
Note: it cannot be written as <! [CDATA [or <! [CDATA [
6. XML Processing of white space and line feed
1. the blank part is not automatically deleted by the parser.
2. The new line is always identified as LF (line feed, line feed ).
In Windows applications, new lines in text are often identified as Cr, LF (carriage return, line feed, carriage return, and line feed ).
In UNIX applications, the new line is often identified as LF. Some applications only use CR to represent a new line.
VII. Entity
1. The entity is the storage unit of XML, and is a variable used to define shortcuts for common text, instead of character data.
2. Internal entities: Exists in the declared document;
External entity: Use an identifier to point to a bucket outside the document;
System external entities: Reference local computers or networks;
Public external entities: Reference public computers or networks;
3. objects are divided into the following parts based on the position where the document appears:
① General entity: any position
Internal entity:
<! Entity entity name "replace content">
External entity:
<! Entity Object Name System "test.txt (replace file name)">
<! Entity object name public "test.txt (replace file name)">
② Parameter entity: In DTD
It cannot be used in documents, but only in DTD.
<! Entity % entity name "replace content">
4. Object Declaration
The object must be declared in the doctype declaration.
Syntax:
<? XML version = "1.0" endcoding = "gb2321"?>
<! Doctype name [
Entity Declaration
....
]>
<Root element>
</Root element>
5. Object Reference:
① General entities:
The object must be declared before being referenced. You can reference an internal object in the attribute.
Syntax:
& Entity name;
Example:
...
<! Entity name "Zhang San">
...
<MSG>
& Name;
<Body>
Hello!
</Body>
<First>
& Name;
</First>
</MSG>
② Parameter entity:
Syntax:
% Entity name;
8. XML document Specification
1. All XML documents must have at least one element.
2. xml labels are case sensitive.
3. All XML document tags must have an end tag.
4. Correctly nest tags.
5. Label naming rules: a combination of characters, numbers, periods, colons, underscores, and connectors (-) Starting with an underscore (-). It cannot contain spaces and cannot start with a reserved word.
6. Attributes cannot be repeated and values are separated by quotation marks. The name rules and labels are the same.
7. Documents should be verified.
And so on