Web Services Application Development Study Notes (1): XML Overview

Source: Internet
Author: User
Content 1.What is XML? 2. xmlBasic Features 3. Html And XML Differences 4. xmlDocument Structure  
1.What is XML?

XML (eXtensible Mark Language) is a markup language. It is a cross-platform, content-dependent Technology in the Internet environment and an effective tool for processing distributed structure information.

To put it simply, XML is similar to the HTML markup language used to describe data. tags are not pre-defined and can be customized. You can use the document type definition (DTD) or schema) to describe data. You can see from the HTML page that HTML follows the http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtddocument.

 

2. xmlBasic Features

(1) XML can separate data from HTML, that is, it can store data outside HTML files in XML documents, so that developers can focus on using HTML to display and layout data, make sure that the HTML file does not need to be modified when the data is changed to facilitate page maintenance.

(2) XML can be used to exchange data. Converting data to XML format for storage can greatly reduce the complexity of data exchange, and make the data be differentProgramRead.

(3) data can be shared using XML. XML data is stored in plain text format, which makes XML easier to read, record, and debug, and makes data sharing between different systems and programs easier.

3.Previously learned htmlAnd XMLWhat is the difference?

Item

XML

Html

Scalability

Scalable, able to define new tag Elements

Not scalable, marking elements are fixed

Focus

Focuses on Structured description data

Focuses on how to display data

Syntax

Strict syntax, requiring tag nesting, pairing, and compliance with the DTD (Document Type Definition) Tree Structure

Tag nesting, pairing, and so on are not required. There is no need to have a certain order between tags.

Readability

Clear structure and easy to read

Hard to read

Maintainability

Easy to maintain

Difficult to maintain

Data and display relationships

Data Description and display mode are separated

Integration of data and display

4. xmlDocument Structure

The XML document consists of two parts: the preface and the document elements.

XMLDeclaration statements usually have the following attributes:

Version: This attribute must be local and lowercase. It is used to indicate the XML version. The parser has a different version for parsing. Currently 1.0 is used.

Encoding: This attribute is optional and used to indicate the character encoding method used in this document. However, it is recommended that you write it during development to prevent garbled characters. XML supports multiple character set types, such as the encoding method gb2312, UTF-8, etc.

Standalone: This attribute defines whether the document can be processed without reading any other files. The attribute value can be yes or no. If the XML document does not reference any other files, you can specify standalone = "yes"; otherwise, standalone = "no ". The default value of standalone is no.

XMLDocument Content:

(1)The body is generally composed of root elements, child elements, attributes, comments, and content.

(2)XML Element naming rules:

A. The element name can contain characters, numbers, and other valid characters, and is case sensitive.

B. The element name cannot start with a number or punctuation.

C. The element name cannot start with XML (or XML.

D. The element name cannot contain spaces and avoid special characters such as "-", ".", and.

E. Element naming should follow the simple and easy-to-read principle.

F. If the XML document corresponds to a data table, try to keep the element name in the XML document and the field name in the database always = to facilitate data exchange.

We recommend that you use English letters for naming.

(3)There are four types of XML element types:

A. Empty Element

If an element does not contain any text or child elements, it is an empty element.

 
 <Student> </Student>

 

B. Only text elements

Some elements contain text content.

 
<Name>Terrychan</Name>

<Age>21</Age>

 

C. Only child elements

An element can contain other elements. The container element is called the parent element and the contained element is called the child element.

<Student>

<Name>Terrychan</Name>

<Age>21</Age>

</Student>

 

D. The hybrid element contains both text and child elements.

<Student>

Junior

<Name>Terrychan</Name>

<Age>21</Age>

</Student>

(4)XML attributes

XML elements can have attributes. An attribute is a further description and description of a tag. A tag can have multiple attributes. Its basic format:

<Element name attribute name = "attribute value">

In XML, attributes can be rewritten as nested child elements. For exampleCode:

 <StudentSex= "Male">

<Name>Terrychan</Name>

<Age>21</Age>

</Student>

 

It can be rewritten

<  Student  > 

< Sex > Male </ Sex >

< Name > Terrychan </ Name >

< Age > 21 </ Age >

</ Student >

Note: In XML, it is best to avoid using attributes. When attributes are used, attributes cannot contain multiple values (but can be sub-elements), attributes cannot be easily extended, and attributes cannot describe the structure (but sub-elements can) when using program code for processing, attributes are more difficult to parse than elements, attribute values are difficult to test through DTD, and attributes are used to store data. XML documents are more difficult to read and operate.

(5)Note

Annotation Syntax: <! --Here is the comment information->

(6)Character reference and entity reference

Character reference: during actual processing, characters that are not on the keyboard or graphical characters cannot be directly entered. In this case, you can use Unicode codes to add them as character references.

 <?  XML version = "1.0" encoding = "UTF-8"  ?> 
< Chars >
< Ch > & #169; </ Ch >
< Ch > & # Xa9 </ Ch >
< Ch > & #174; </ Ch >
</ Chars >

 

Entity reference: allows you to insert any string into element content or attribute values. This provides an alternative for character reference.

Entity

Purpose

& Lt;

It is usually used to replace a smaller sign (>)

& Gt;

Usually used to replace a greater than sign (<)

& Amp;

It is usually used to replace characters (&)

& Quot;

It is usually used to replace double quotation marks (")

& Apos;

It is usually used to replace single quotes (')

 <?  XML version = "1.0" encoding = "UTF-8" ?> 

< Chars >

< Ch > & Lt; </ Ch >

< Ch > & Gt; </ Ch >

< Ch > & Amp; </ Ch >

< Ch > & Quot; </ Ch >

< Ch > & Apos; </ Ch >

</ Chars >

(7)CDATA section

 Generally, to insert special characters (such as <,>, &) into the character data of an element, you can use a character reference or a predefined generic Entity reference.

CDATA section uses "<! [Cdtat ["starts and ends with"]>. You can enter any character except "]>" between the two character groups.

 

Author: forevernome
Source: http://www.cnblogs.com/ForEvErNoME/
You are welcome to repost or share it, but be sure to declare it Article Source. If the article is helpful to you, I hope you can Recommendation Or Follow

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.