1. XML definition
Extensible markup language, a subset of the standard general markup language, referred to as XML. Is a kind of markup language used to mark electronic documents to make them have structure.
2. XML presentation
The following is a tag display of XML. XML is inaction. XML is designed to structure, store and transmit information, so we can tag freely. Only what meaning we give it will have any meaning. xml is used to simplify data sharing, data transmission and platform change.
<xml> <tag>label</tag> <parent> <son>Son</son> <daughter>daughter</daughter> </parent> <famliy>xml big family</famliy> </xml>
3. XML document instance
The XML document must contain a root element. This element is the parent of all other elements.
The elements in the XML document form a document tree. The tree starts at the root and extends to the bottom of the tree.
encoding="utf-8" specifies the encoding of the xml document.
<?xml version="1.0" encoding="utf-8"?> <xml> <tag>label</tag> <parent> <son>Son</son> <daughter>daughter</daughter> </parent> <famliy>xml big family</famliy> </xml>
4. Other features of XML
- It is illegal for xml to omit the closing tag. All elements must have a close tag < son > son < / son >
- An element can contain other elements, text, or a mixture of both. Elements can also have attributes that provide additional information about the element.
<parent> Parent owned <son sex="Attribute: Male">Son</son> <daughter sex="Attribute: Female">daughter</daughter> </parent>
5. XML validation
XML with correct syntax is called "well formed" XML.
The XML validated by DTD is "legal" XML.
W3C supports a DTD substitute based on XML, which is called XML Schema, so the DTD specification has been basically eliminated. Now we mainly use XML Schema, that is, XML Schema is a definition that can describe the structure of XML documents. If your XML file follows an XML Schema, you can formulate the following XML Schema in the XML file, XML Schema language can also be referenced as XSD (XML Schema Definition).
<?xml version="1.0"?> <xml xmlns="http://www.springsun.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springsun.com xml.xsd"> <tag>label</tag> <parent> <son>Son</son> <daughter>daughter</daughter> </parent> <famliy>xml big family</famliy> </xml>
Where xmlns is the default namespace, xmlns:xsi is an industry default standard, which is used to define an XML schema instance, and xsi:schemaLocation points to a location accessible to XSD.
6. XML namespace
In XML, the element name is freely defined by us. When two different documents use the same element name, there will be naming conflict. Therefore, in order to distinguish, the label can be prefixed.
<s:xml> <s:tag>label</s:tag> <s:parent> <s:son>Son</s:son> <s:daughter>daughter</s:daughter> </s:parent> <s:famliy>xml big family</s:famliy> </s:xml>
The namespace is to add this prefix. xmlns is used at the root node to specify that the prefix corresponds to a specific identity to make it meaningful.
<s:xml xmlns:s="http://www.springsun.com"> <s:tag>label</s:tag> <s:parent> <s:son>Son</s:son> <s:daughter>daughter</s:daughter> </s:parent> <s:famliy>xml big family</s:famliy> </s:xml>
http://www.springsun.com The address used to identify the namespace. Its only function is to give the namespace a unique name, but the industry is identified by a web page link. Why don't we add a prefix like xmlns:s in the examples we usually see, because if: s is not added, the default namespace is identified, and all subsequent elements without a prefix are under this namespace.
7.0 XSLT display XML
Use XSLT to display xml: use XSLT to convert the xml file into HTML before the browser displays it, so that the xml data can be displayed on the web page in a custom style.
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="xml.xsl"?> <xml xmlns="http://www.springsun.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springsun.com xml.xsd"> <tag>label</tag> <parent> <son>Son</son> <daughter>daughter</daughter> </parent> <famliy>xml big family</famliy> </xml>
<? xml-stylesheet type="text/xsl" href="xml.xsl"?> This tag is used to convert XML into html in the style of xml.xsl. If the browser supports XSL, it can be displayed directly (basically supported by browsers). XSL can view the special introduction.
The above can provide a quick introduction to xml. You can retrieve some other knowledge when you use it, such as CDATA, XML DOM, XPath, etc.