Xml
Understanding XML will help you understand why it is the perfect choice to build Web applications
If you already have your own personal website or your own company website, or if you have a good understanding of the Web, you may have noticed a crazy discussion about a new web technology---XML. After Microsoft released the IE5 (the first commercially available browser to support XML standards) earlier this year, this frenzy of enthusiasm has become a reality for everyone to compete. Here, you may ask yourself a very important question:
1. What is XML?
XML is the abbreviation for Extensible Markup Language (extensible Markup Language). Like HTML, XML is from the meta language of all markup languages---standard generic markup Language SGML (Standard generalized Markup Language) there derived from it. SGML is a meta language, it can also be called a system that defines a markup language such as HTML. XML is also a meta language, a subset of SGML that defines a Web application. Like SGML, you can also use XML to define different markup languages to meet different needs, particularly in terms of data performance.
With the development of Web applications, the limitations of HTML are more and more obvious:
First, HTML is a kind of interface technology: It mixes data and data representations, which makes it difficult to separate the two.
It has a complex set of tags: you can't extend it with your own specific application tag.
It's "flat": You can't specify a hierarchy of data to represent details such as inclusion, importance, etc.
It cannot simply transmit the data to the client for further processing by the client itself. In fact, HTML is always generated on the server side, and the client is just a display machine.
It can only provide a way to show you the data. If you want to provide a different display, you'll have to recreate the data and the full HTML page on the server side, so that you can display it on the client. If the data and display form are separated, you will be able to download the data to the client, Then randomly send a different display of the data to your needs.
It's not readable, either as a person or as a computer reader. HTML is also not very rigorous. Some tags need to match the start and Terminator
(like <body> and </body>), but there are also some only start characters with no Terminator (like <p> and <b>). The HTML interpreter had to deal with these somewhat random formats.
HTML and XML are the standard set by the world Wide Web Consortium. Members of the consortium realize that with the rapid development of the Internet, it is necessary to find a way to separate data and Web pages----so XML was born. Why not just use SGML? I don't want to enumerate the annoying details here, but there are plenty of reasons to prove that SGML is quite complex ( It has a description of more than 500 pages); The XML standard is far simpler than it is (only a few 26 pages).
Although strictly speaking, XML is just a data label specification language, it has begun to gradually include a series of related technologies, like XML Dom,xsl,xll,xml Namespaces and VML. In this article, we'll see xml,xsl (extensible Style Language extensible Formal language), and the XML DOM (Document Object model) is the advanced technology, we will also introduce other standards.
2. Parse an XML file
The XML 1.0 standard can be found on the Www.w3.org/TR/REC-xml Web site. But note that although it is not the best place to learn XML, after you read this article, please look at it again, I believe you will have a deeper understanding.
Before looking at the first example, let's familiarize ourselves with the naming system for XML. Similar to HTML, an XML start tag is such a declared < tag. The end tag is similar, but add a front slash </tag after the less than number. A label pair and what it contains , like the <movie>gone with the wind</movie> all things in a start tag and an end tag are called the contents of an element. In the example above, the Gone with the Wind is the movie of this element. The beginning tag of XML can also be a list of attributes, like <tag attribute1= "attribute2=".
If the XML file follows the basic Standard Rules (described in more detail later), then they are well-formed XML files. The most basic rule to follow is that every element that has a start tag must have a corresponding end tag, and the end tag of the child element must precede the closing tag of the parent element that contains it. .
For example, this is not the form of a rule:
<auction_item>
<description>
</auction_item>
</description>
And this is in the form of a rule:
<auction_item>
<description>
</description>
</auction_item>
There is a complete and detailed list of rules in the XML standard of the consortium. A well-formed XML file must contain at least one element. In other words, the file must have a root element (not an element in any other element). This makes each XML file a hierarchical list of elements. The XML file defines the hierarchical relationship between the elements (parent-child, sibling) by placing the elements in other tag pairs.
To illustrate this point, let's look at an example:
Table A:xml Air route Data sample
<?xml version= ' 1.0 '?>
<!--This is a example of airline flights in XML-->
<flight_schedule>
<flight flight_number= "1073/61" >
<origination>
<city> --> Raleigh, NC </city>
<airport> RDU (Raleigh Durham Intl.) </airport>
</origination>
<destination>
<city> San Francisco </city>
<airport> SFO (San Francisco Intl.) </airport>
</destination>
<connection>
<city> Charlotte, NC </city>
<airport> CLT </airport>
</connection>
<airline> US Airways </airline>
<price>1492.00</price>
<aircraft>
<manufacturer> Boeing </manufacturer>
<model> 747 </model>
</aircraft>
<movie> No </movie>
<meal> Dinner </meal>
<departure_time> 11:00 </departure_time>
<arrival_time> 14:00 </arrival_time>
</flight>
<!--more flights would go to this check the data file for a example-->
</flight_schedule>
Table A is some of the airline's shipping data expressed in XML format. You can see that XML is relatively readable. tags and their content are quite self contained. What if it's in an HTML form?
It's almost impossible for you to separate the data from the Web. But in the XML format, we can easily use a travel agent to get the data, save it in a database, or reformat its display.
Now let's further dissect the example. The first line is the standard title for XML:
<?xml version= "1.0"?>
This title tells the handler (here refers to the IE5 XML interpreter and the browser) this is an XML file, and declares which XML version the file conforms to (up to now only version 1.0).
The next line of the file is a comment:
<!--A example of airline flights in xml-->
XML has the same annotation format as HTML, which you might already be familiar with. But unlike HTML, all start tags in an XML file must match an end tag, so the start tag in the hierarchy header <flight_schedule> Must have a matching end tag, </flight_schedule>, at the end of the file.
The rest is a series of elements defined by the start and end tags. This example describes a flight schedule with two flights. Each flight contains the hierarchical data shown below:
Origination
City
Airport
Destination
City
Airport
Connection
City
State
Airport
Airline
Price
Aircraft
Manufacturer
Model
Departure_time
Arrival_time