20150131--xml on

Source: Internet
Author: User
Tags cdata processing instruction

The universal Data transmission format--xml on

Directory

Universal Data transmission Format--xml ... 1

I. Introduction to XML ... 3

1. Historical Origins ... 3

2. What is XML 3

3. The difference between XML and HTML ... 4

4. XML Application Scenario ... 4

1) Middleware (communication standard) that acts as an interaction between programs ... 4

2) configuration file ... 4

3) Small Database ... 4

4) canonical data Format (dtd+xml) ... 4

5. The principle of XML transmission ... 5

Second, the basic syntax of XML ... 5

1. Quick Start ... 5

2. XML Basic Syntax ... 7

1) Document Declaration ... 7

2) elements (tags, tags) ... 7

3) Element Properties ... 8

4) Comments ... 9

5) Special Characters ... 10

6) CDATA Segments (CDATA sections) ... 11

7) processing Instruction Pi 11

3, Expansion: In-vehicle system RSS Implementation ... 12

Third, DTD constraints ... 14

1. Why DTD constraints are required ... 14

2. What is a DTD? 14

3. Quick Start ... 15

4. DTD Constraint document Classification ... 15

1) Internal DTD: 15

2) External DTD: 16

3) Public DTD: 17

5. DTD constraint--element (tag, tag) definition ... 18

6. DTD constraint--attribute definition ... 19

1) Property Type ... 20

2) Default Value ... 21st

7. DTD constraint--Define entity ... 23

1) Referencing entities ... 24

2) Parameter entity ... 24

8, comprehensive case ... 251. Introduction to XML 1, historical origins

GML (1969)->SGML (1985)->html (1993)->xml (1998)

GML: Universal Markup Language

IBM 1969 Brick Family to work on a topic: How a program works in multiple systems (System portability)

SGML: Standard Universal Markup Language

IBM 1985 upgrades Basic GML

HTML: British scientist Beaune Lee defined 20 HTML tags in SGML to implement the world's first web page

html:1993 for promotion and use

xml:1998 Year 2, what is XML

Xml

Full name: Extensible Markup Language

Chinese name: Extensible Markup Language

Used to tag electronic files with a structured markup language that can be used to tag data, define data types, and allow users to define their own markup language as the source language.

<body></body>

< games ></Games >

Interview question: What is the main purpose of Xml,xml?

A: Extensible Markup language, XML for transmitting data and storing data. 3. Differences between XML and HTML

1) HTML tags can not be customized, from the label can not achieve "see the meaning of the word" purpose

<table></table>

< form ></form >

2) HTML binds the data to the format

XML is only responsible for the transmission and storage of data, and its label does not make any sense

3) different browsers to solve HTML differences

HTML syntax requirements are not strict

Wait a minute

HTML is mainly used for the display of data, XML is mainly used to transfer 4, XML Application scenario 1) as a middleware for inter-program interaction (communication standard)

Express 100 Interface (Java) XML PHP 2) configuration file

config.php PHP

Config. php, Java, C # 3) Small database

Php+mysql PowerWord

Php+xml PowerWord 4) canonical data Format (Dtd+xml)

Phpexcel

1 2 3 4

Product number Product Name Product quantity Product Unit Price

itcast001 PHP Tutorial 100 998 5, XML transfer principle

Second, XML basic Syntax 1, Quick Start

Describe a person's information

Operating effect:

Description of the book information

Operating effect:

Description: There are two types of XML run debugging methods:

The first type: Right-click on the XML document, open the way to select the browser to open directly

The second type: directly in the browser address bar to enter the URL, direct access to 2, XML basic syntax

L Document Declaration

L Element

L Element Properties

L Notes

L Special Characters

L CDATA Section

L processing instructions 1) Document Declaration

You need to use document declarations to declare XML documents first

The simplest syntax:

L <?xml version= "1.0" encoding= "Utf-8"?>

L Version 1.0 (represents the version of the current XML document)

L encoding encoding format (encoded format utf-8, BIG5, gb2312)

L Standalone is independent (depends on DTD file) default Yes

Function: tells the browser to interpret the version and format of the information 2) elements (tags, tags)

L A label is divided into start and end tags (cannot be omitted)

Error:<title> Kingdoms

Correct:<title> kingdoms </title>

<title/>

L can nest several sub-tags in a label, but all tags must be properly nested, not allowed to have cross nesting

Fatal error:<title><price></title></price>

Correct:<title><price></price></title>

L An XML document must have only one root tag, and all other tags are sub-tags of this root tag

Naming rules for elements

The name of the L element (label) can contain letters, numbers, minus signs, underscores, and periods

The right:<abc></abc>

Wrong: <[email Protected]#></[email protected]#>

l strict case sensitivity;

The right:<abc></abc>

Wrong:<abc></abc>.

L can only start with letters or underscores;

The right:<abc123></abc123>

Wrong:<123abc></123abc>.

L cannot have spaces or tabs between the name characters;

The right:<abc></abc>

Wrong: <a b c></a B c>

L cannot use colons between name characters

The right:<abc></abc>

Error:<ab:c></ab:c> 3) element attribute

L An element can have multiple properties

L attribute values must be enclosed in quotation marks (single or double quotation marks)

The naming specification of the L property name is the same as the element's naming convention

The properties in the L element are not allowed to be duplicated

The information represented by the label attribute can also be changed to describe it in the form of a child element.

4) Notes

Basic syntax:

<!-Comment Content--

Note: XML declarations cannot be preceded by comments, annotations cannot be nested

Operating effect:

5) Special characters

Take a look at the example:

We found in the runtime that the system found an error in line 7th, mainly because of the special characters in the system caused the browser to be unable to parse the special characters, how to solve?

A: You can use the following characters instead of special characters in an XML document

Description: The fourth character represents a single quotation mark

The above error cases can be solved in the following ways:

6) CDATA Segments (CDATA sections)

Cdata:character Data

Function: Treat the label as plain text content

Syntax: <! [Cdata[content]]>

Example code:

For special characters and CDATA sections, compare?

Common denominator: All are used for conversion of special characters

Different points: Special characters can only be used for less data, such as less than, greater than the number of cases

CDATA sections can be used for conversion of large quantities of data, such as article description, article content, etc. 7) processing instruction PI

Function: Mainly used for the display of XML data

Role: Used to direct how the software parses an XML document.

Syntax: Must be "<?" As the beginning, with "?>" as the end.

Common Processing Instructions:

XML directives

Xml-stylesheet directive: Call the corresponding CSS display data

Example: <?xml-stylesheet type= "Text/css" href= "Style.css"?>

XML Sample code:

STYLE.CSS Code

3. Extension: RSS implementation in vehicle system

RSS: is a subscription service, in many sites such as (Sina, NetEase) and other systems can be seen

In the website system can provide an API interface, to achieve the output of RSS information

1) RSS BASIC structure

By reading the RSS book, you can determine that RSS is also a special XML-based format

In the XML document, define the document declaration

2) Loading RSS format

Under document declaration, load the RSS format

3) Define channel display label

4) Define RSS content (define item label)

The results are as follows:

20150131--xml on

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.