XML Language Basics

Source: Internet
Author: User
Tags cdata processing instruction xml parser

XML Language1. What is XML?

1.1 XML:

Extensible Markup language Extensible Markup Language. XML technology is published by the organization, followed by the norms of the organization. What problems does 1.2 XML technology solve?
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <China>3     <China>4     <Hunan>5         <Changsha></Changsha>6         <Zhuzhou></Zhuzhou>7     </Hunan>8     <Hubei>9         <Wuhan></Wuhan>Ten         <Huang Gang></Huang Gang> One     </Hubei> A </China>

The fundamental goal of the XML language is to describe the kind of relational data that often occurs in real life.

The XML language allows users to calculate custom tags, label format references.

  1.3 XML Common applications

(1) for storing relational data

(2) Software configuration file to describe the relationship between program modules

  1.4 XML syntax  

(1) Document declaration

<?xml version= "1.0" encoding= "GB2312" standalone= "yes"?>

Note: The encoding property describes the character encoding of the document, and the standalone property describes whether the document is independent

(2) elements

(i) an XML element refers to a label that appears in an XML file, a label that is divided into a start tag and an end tag, and a label that has the following forms of writing, for example:

Contains the label body:<a>hello</a>

Without tag body: <a></a>, abbreviated to:<a/>

(ii) Several sub-labels can also be nested within a tag. However, all tags must be properly nested and never cross-nested.

(iii) A well-formed XML document must have only one root tag, and the other tag is the descendant tag of the root tag.

(IIII) for all whitespace and line breaks that appear in the XML tag, the XML parser is treated as a label content. As shown below :

      

1 <? XML version= "1.0"  encoding= "UTF-8"? standalone= "yes" >23<xml-body>  4    <a>www.baidu.com</a>                5    <a>   6        www.baidu.com    <!--a carriage return with a newline and a space--7    </a>     8</xml-body>

Writing specifications   

(i) An XML element can contain letters, numbers, and other visible characters, but must adhere to some of the following specifications:

(ii) Case-sensitive, such as,<p> and <p> are two different markers.

(iii) cannot start with a number or "_" (underscore).

(IIII) cannot start with XML (or XML, or XML, and so on).

(IIIII) cannot contain spaces.

The middle of the name cannot contain a colon (:).

(3) Properties

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 quotation marks (") or single quotation marks (').

Defining attributes must follow the same naming conventions as labels

In XML technology, the information represented by the tag attribute can also be changed to be described in the form of a child element, for example:

<input>

<name>text</name>

</input>

(4) Notes

The comments in the XML file are in the format "<!--annotated--".

Note: XML declarations cannot be nested without comment annotations, for example:

<!--Large segment notes

......

<!--local comments--

......

-

(5) CDATA Area , special characters

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 for content within a CDATA region, the XML parser does not process, but is directly intact output.

Syntax: <! [Cdata[content]]>

<! [cdata[

<a>

<br/>

</a>]]>

    

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Hel>3     <! [Cdata[4 <A> Hello! </A> <! --the content inside will not be parsed--5     ]]>6     <A1>Hello the world Little King</A1>7     <B1>XML Language Small Sheet</B1>8 </Hel>

For some individual characters, if you want to display their original styles, you can also use escape as a way to handle them.

    

(6) processing instructions (processing instruction )

Processing instructions, referred to as pi (processing instruction): The processing instruction is used to direct the parsing engine to parse the 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 XML document content. <?xml-stylesheet type= "Text/css" href= "Test.css"?>

The processing instructions must be "<?" At the beginning, with "?>" as the end, the XML declaration statement is the most common kind of processing instruction.

  

1 <?XML version= "1.0" encoding= "gb2312"?>2 <?xml-stylesheet type= "text/css" href= "Test.css "?>3 <Hel>4     <A1>Hello the world Little King</A1>5     <B1>XML Language Small Sheet</B1>6 </Hel>
Test.css
a1{ font-size:50px; color:red;} b1{ font-size:80px; Color:green;}

Note: The encoding problem: the encoding set in the XML file must be the same as when saving to the local file encoding, otherwise it will appear garbled.

  

Is the reason for garbled. The coding will certainly be garbled.

   

      

XML Language Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.