XML allows you to create such labels by yourself. This is called extensibility. All XML languages must undergo HTML conversion before they can run on the browser.
XML makes it easier to use the SGML language on the network "simple and direct": it simplifies the process of defining file types and simplifies the process of programming and processing SGML files, it simplifies transfer and sharing on the web.
XML is more suitable for tree data
XML is very simple and easy to learn. If you are familiar with HTML, you will find that its documentation is very similar to HTML. See the example document:
? XML version = "1.0"?> <Br>
<Myfile> <br>
<Title> XML Quick Start </title> <br>
<Author> Ajie </author> <br>
<Email> ajie@aolhoo.com </Email> <br>
<Date> 20010115 </date> <br>
</Myfile>
The first line is an XML declaration, indicating that the document complies with the XML 1.0 specification.
The second line defines the first element in the document, also known as the root element: <myfile>. This is similar to the <HTML> Start mark in HTML. Note that this name is customized by yourself.
The following four sub-elements are defined: title, author, email, and date. The title, author, email address, and date of the article are described respectively. Of course, you can define these labels in Chinese to make it easier to understand:
<? XML version = "1.0" encoding = "gb2312"?>
<Article>
<Title> XML easy learning manual </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Article>
This is the XML document. Anyone familiar with HTML can directly write such a simple XML document.
The XML language itself is relatively simple, and some scripting languages are also required in HTML conversion.
Below is the Javascript
<HTML>
<Head>
<Script language = "JavaScript" for = "window" event = "onLoad">
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. async = "false ";
Xmldoc. Load ("myfile. xml ");
Nodes = xmldoc.doc umentelement. childnodes;
Title. innertext = nodesitem (0). text;
Author. innertext = nodes. Item (1). text;
Email. innertext = nodes. Item (2). text;
Date. innertext = nodes. Item (3). text;
</SCRIPT>
<Title> call XML data in HTML </title>
</Head>
<Body bgcolor = "# ffffff">
<B> title: </B>
<Span id = "title"> </span>
<B> author: </B>
<Span id = "author"> </span>
<B> mailbox: </B>
<Span id = "email"> </span>
<B> date: </B>
<Span id = "date"> </span>
</Body> <br>
</Html> <br>
2. Save the following code as myfile. xml
<? XML version = "1.0" encoding = "gb2312"?>
<Myfile>
<Title> XML easy learning manual </title>
<Author> Ajie </author>
<Email> ajie@aolhoo.com </Email>
<Date> 20010115 </date>
</Myfile>
XML format:
1. All tags must have an ending mark;
2. All XML tags must be reasonably nested;
3. All XML tags are case sensitive;
4. All marked attributes must be included in;
Therefore, the correct syntax of the preceding statement in XML is:
1.
Sample
2. <B> <I> sample </I> </B>
3. <TD> sample </TD>
4. <font color = "red"> samplar </font>
In addition, the XML tag must follow the following naming rules:
1. the name can contain letters, numbers, and other letters;
2. The name cannot start with a number or underscore;
3. The name cannot start with XML (or XML;
4. The name cannot contain spaces.
An XML statement consists of elements, tags, attributes, and metadata. Many words are the relationship between trees and leaves.
1. element ):
We have some knowledge about the element in HTML. It is the smallest unit of HTML documents, and it is also the same in XML. An element is defined by an identifier, including the start and end identifiers and the content, as shown in the following figure: <author> Ajie </author>
The only difference is that in HTML, the identifier is fixed, and in XML, the identifier needs to be created by yourself.
2. Tag)
An identifier is used to define an element. In XML, the identifiers must appear in pairs to enclose the data in the middle. The name of the identifier is the same as that of the element. For example, an element:
<Author> Ajie </author>
<Author> indicates the identity.
3. attribute ):
What is an attribute? See this HTML code: <font color = "red"> word </font>. Color is one of the attributes of font.
An attribute is a further description and description of an identifier. An identifier can have multiple attributes, such as the font attribute and size. The attributes in XML are the same as those in HTML. Each attribute has its own name and value. attributes are part of the identifier. Example:
<Author sex = "female"> Ajie </author>
The attributes in XML are also defined by yourself. We recommend that you change the attributes to sub-elements instead of using them. For example, the code above can be changed to the following:
<Author> Ajie
<Sex> female </sex>
</Author>
The reason is that attributes are not easy to expand or be operated by programs.
4. Declaration (Declaration)
There is an XML declaration in the first line of all XML documents. This statement indicates that this document is an XML document that complies with the XML version specification. An XML statement is like this:
Documents in good format must begin with an XML declaration, for example:
<? XML version = "1.0" standalone = "yes" encoding = "UTF-8"?>
Here, you must describe the XML version that the document complies with. Currently, it is 1.0. Secondly, it indicates that the document is "independent" and does not need a DTD file to verify whether the identity is valid. Third, description of the language used in the document. The default is UTF-8. If you use Chinese, you need to set it to gb2312
A well-formed XML document must have a root element, that is, the first element created after the declaration. Other elements are child elements of the root element and belong to a group of root elements.
The XML syntax must be followed when writing the content of an XML document in good format.
I. XML syntax rules
Ii. Element syntax
3. annotation syntax
Iv. CDATA syntax
V. namespaces syntax
6. entity syntax
VII. DTD syntax
The XML document is similar to the original HTML code and uses an identifier to identify the content. To create an XML document, follow these important rules:
Rule 1: an XML declaration statement is required.
We mentioned this in the previous chapter. Declaration is the first sentence of the XML document. Its format is as follows:
<? XML version = "1.0" standalone = "yes/no" encoding = "UTF-8"?>
The purpose of the Declaration is to tell the browser or other processing programs that this document is an XML document. The version in the declaration statement indicates the version of the XML specification that the document complies with; standalone indicates whether the document has a DTD file, and if so, the parameter is no; encoding indicates the language encoding used by the document, which is the UTF-8 by default.
Rule 2: whether a DTD file exists
If the document is a "valid XML document" (see the previous chapter), the document must have a corresponding DTD file and strictly abide by the specifications set by the DTD file. The declaration statement of the DTD file follows the XML declaration statement in the following format:
<! Doctype type-of-Doc system/Public "DTD-name">
Where:
"! Doctype "indicates that you want to define a doctype;
"Type-of-Doc" is the name of the document type, which is defined by you and is usually the same as the DTD file name;
"System/Public" only uses one of the two parameters. System refers to the URL of the private DTD file used by the document, while public refers to the URL where the document calls a public DTD file.
"DTD-name" is the URL and name of the DTD file. The suffix of all DTD files is ". DTD ".
We should use the following example to write it as follows:
<? XML version = "1.0" standalone = "no" encode = "UTF-8"?>
<! Doctype filelist System "filelist. DTD">
Rule 3: Pay attention to your case sensitivity
In XML documents, the Case sensitivity is different. <P> and <p> are different identities. Note that when writing elements, the front and back identifiers must be the same in case. For example, <author> Ajie </author> is incorrect.
You 'd better develop a habit, either in upper case, or in lower case, or in upper case, the first letter. This reduces document errors caused by case-insensitive.
Rule 4: quote the property value
In HTML code, attribute values can be enclosed by quotation marks or not. For example, <font color = Red> word </font> and <font color = "red"> word </font> can be correctly interpreted by the browser.
However, in XML, it is stipulated that all attribute values must be enclosed in quotation marks (single or double quotation marks). Otherwise, it will be regarded as an error.
Rule 5: All identifiers must have end identifiers.
In HTML, tags may not appear in pairs? Lt; br>. In XML, all identifiers must appear in pairs. If there is a start identifier, there must be an end identifier. Otherwise, it is regarded as an error.
Rule 6: All empty identifiers must also be disabled.
An empty ID is an identifier with no content between the identifiers. Such as <br> and . In XML, all identifiers must have end identifiers. For such empty identifiers, the XML processing method is to add/at the end of the original identifiers. For example:
<Br> it should be written as <br/>;
<Meta name = "keywords" content = "XML, SGML, HTML"> enter <meta name = "keywords" content = "XML, SGML, HTML"/>;
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. Attributes can be used for further description.
There are no reserved words in XML, so you can use any words as element names as you like. However, the following rules must also be observed:
1. the name can contain letters, numbers, and other letters;
2. The name cannot start with a number or underscore;
3. The name cannot start with the letter XML (or XML ...).
4. The name cannot contain spaces.
5. The name cannot contain ":" (colon)
To make the elements easier to read, understand, and operate, we also have some suggestions:
1. Do not use "." in the name ".". In many programming languages, "." is an attribute of an object, for example, 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.
4. The name can contain non-English characters, such as Chinese characters. However, some software may not. (Ie5 currently supports Chinese elements .)
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:
<! [CDATA [place the characters to be displayed here]>
For example:
<! [CDATA [<author sex = "female"> Ajie </author>]>
The content displayed on the page will be "<author sex =" female "> Ajie </author>"