1.XML and HTML are designed for different purposes:
XML is designed to transmit and store data , and its focus is on the content of the data . HTML is designed to display data , and its focus is on the appearance of the data. HTML is designed to display information, and XML is designed to transmit information. In the XML language, it allows the user to customize the label. A label is used to describe a piece of data.
2.XML Common applications
L XML technology is often used as a software configuration file to describe the relationship between program modules, in addition to storing relational data.
L in a software system, to improve the flexibility of the system, the modules it starts are usually determined by its configuration file
3.XML Document Rules
Classification of XML documents
Malformed (malformed) XML document: an XML document that has absolutely no adherence to the basic specification of an XML document.
Well-Formed (well-formed) but invalid XML document: an XML document that adheres to the basic specification of an XML, but does not use a DTD or schema to define semantic constraints.
valid (valid) XML documents: adhere to the basic specification of an XML document and use a DTD or schema to define semantic constraints, and also fully adhere to XML documents with DTD or schema-defined semantic constraints.
• Well-Formed XML document
Well-Formed or well structured XML documents have the correct syntax.
Well-Formed (well formed) XML documents adhere to the XML syntax rules:
The XML document must have a root element
The XML document must have a close tag
XML tags are case sensitive
XML elements must be nested correctly
XML attribute must be quoted
4.XML syntax
L An XML file is divided into the following sections:
• Document Declaration
• elements
• Properties
• Notes
CDATA area, special characters
• Processing instructions (processing instruction)
l XML Syntax-Document declaration
When writing an XML document, you need to first declare the type of the XML document by using a document declaration. simplest declarative Syntax: <?xmlversion= "1.0"?>
Use the Encoding property to describe the document's character encoding: <?xmlversion= "1.0" encoding= "GB2312"?>
Use the standalone property to describe whether the document is independent: <?xml version= "1.0" encoding= "GB2312" standalone= "yes"? >;ie this property does not work, IE does not read this property.
L Common Errors
1). <?xmlversion=1.0, no double quotes or single quotes
2). <?xml version= "1.0"?> in "and" there is no space between
3). Coding error
Note: The declaration must be the first line of content in the XML document. < cannot have any other characters before
L Elements
An XML element refers to a label that appears in an XML file, one labeled as a start tag and an end tag, and a tag that has several forms of writing, such as a label:
• Include tag body:<a>www.itcast.cn</a>
•:<a/> with no label body
You can also nest several child tags in a label. However, all tags must be reasonably nested, and no cross nesting is allowed, for example:
<a>welcome to<b>www.it315.org</a></b>, wrong ...
well-formed XML documents must have and have only one root tag, and other tags are descendants of this root tag.
XML parsers are processed as label content for all the spaces and lines that appear in the XML tag. For example: The meaning of the following two paragraphs is not the same.
The first segment :< Web site >www.itcast.cn</website >
Second paragraph:
< website >
www.itcast.cn
</website >
Because in XML, spaces and newline are processed as raw content, the "good" writing habits that make the contents of the original file readable by using line-wrapping and indentation can be forced to change when writing an XML file.
an XML element can contain letters, numbers, and other visible characters, but you must adhere to some of the following specifications:
L Case Sensitive , for example,<p> and <p> are two different tags.
L cannot begin with a number or "_" (underscore) .
L cannot begin with XML (or XML, or XML, etc.).
L cannot contain spaces .
The L name cannot contain a colon (:) in the middle.
(1) The English name must begin with an English letter or an underscore, and the Chinese name must begin with a Chinese text or an underscore.
(2) In the case of using the default encoding set, the name can consist of an English letter, a number, an underscore, a connector (-), and a point number (.). In the case of a specified encoding set, the name in addition to the above characters, you can also appear in the character set of legitimate characters
L Property
A label can have multiple properties, each with its own name and value, for example:<input name= "text" >
Attribute values must be enclosed in double quotes (") or single quotes (')
Defining attributes must follow the same naming conventions as labels
Learn more: In XML technology, the information that the label attribute represents can also be changed to describe in the form of a child element, for example:
<input>
<name>text</name>
</input>
L Notes
annotations in the XML file areformatted with the following: "<!--annotation-->" , as in HTML
Note:
No comment before XML declaration
• Annotations cannot be nested, for example:
<!--large section notes
......
<!--local annotation-->
......
-->
L CDATA Area
When writing an XML file, some content may not want the parsing engine to parse execution, but rather as raw content processing. In this case, the content can be placed in a CDATA area, and the XML parser does not process the content within the CDATA area, but rather the output directly intact. Equivalent to the <pre></pre>; syntax format in HTML: <! [cdata[content]]> .... ]]>
L Grammar: <! [Cdata[content]]>
<! [cdata[
<csdn>
<br/>
</csdn>
]]>
L Escape Character
For some individual characters, you can also use an escaped form if you want to display their original styles.
<, > Replace the symbol LT, GT Origin: less than: LessThan; is greater than: GreaterThan abbreviation.
L Processing Instructions
processing instructions, referred to as pi (processing instruction). Processing instructions are used to direct the parsing engine to parse XML document content. For example, you can use the Xml-stylesheet directive in an XML document to notify the XML parsing engine and apply a CSS file to display the contents of an XML document. CSS does not work when the tag name is Chinese.
<?xml-stylesheet type= "Text/css" href= "1.css"?> processing instructions must be " As the beginning, with "?>" as the end, the XML declaration statement is the most common kind of processing instruction.
5. A Case paper
Frist.xml
<?xmlversion= "1.0" encoding= "UTF-8"?>
<?xml-stylesheettype= "Text/css" href= "Frist.css"?>
<code>
<a>
<a1>java Programming </a1>
<a2>csdn</a2>
</a>
<b>
<b1><baidu></b1><!--escape character <> usage-->
<b2>google</b2>
</b>
<! [cdata[
<c>
<c1></c1>
</c>
]]>
</code>
Frist.css
a{
Display:block;
color:red;
font-size:50px;
}
b{
Display:block;
Color:blue;
font-size:30px;
}