Chapter 5: XML instance parsing XML is widely used in different categories, such as MathML in the field of technology, WML for wireless communication, and SVG for network images, here we will focus on the use of XML on the web. XML utilization on the web is important
Chapter 5: XML instance parsing
XML is widely used in different categories, such as MathML in the field of technology, WML for wireless communication, and SVG for network images, here we will focus on the use of XML on the web. XML utilization on the web is important to use its strong data control capabilities. Generally, XML can be used with javascript, asp, and other server programs to meet almost all the usage requirements on the network.
For ease of consideration, we will first introduce a simple example below, which does not contain server programs. The goal is to allow you to have a perceptual knowledge of XML data control.
Well, first [click here] to see the consequences of the instance. (Open it in IE5.0 or a later browser)
This is a simple function of searching CD records. Click "previous" and "next" to view information about a single CD. We can achieve this in two ways:
1. use DHTML to hide data in different layers and display the data by mouse events in sequence;
2. use background programs (such as ASP, CGI, PHP, JSP, etc.) to call the server's real data.
However, in this example, we can see from the original code on the page that the dhtml div is not used, and there is no form action. it is fully implemented using XML. Next we will analyze its production process:
Step 1: define a new ID
Based on the actual CD data, create a new Second, establish its coherent data identification, the resolution is: CD name , Artist, published in the <Year>, Country <Country>, distribution Company <Company> and Price <Price>; finally, a directory named <CATALOG> is created. Why do we need to create another <CATALOG> identifier? Because the XML document requires and can only have one root element (identifier), we have multiple CD data, which is a parallel relationship, therefore, you need to create a root element for these parallel elements. </P> <p> The definitions and relationships of the above elements are completely in line with the XML scale and do not need to be defined in a special DTD file. Therefore, the DTD definition can be omitted. If you want to use DTD to define the process, the process can be as follows: </p> <tbody> Reference content: <br/> <! Element catalog (CD) *> <br/> <! Element cd (Title, Artist, Year, Country, Company, Price)> <br/> <! ELEMENT Title (# PCDATA)> <br/> <! ELEMENT Artist (# PCDATA)> <br/> <! ELEMENT Year (# PCDATA)> <br/> <! ELEMENT Country (# PCDATA)> <br/> <! ELEMENT Company (# PCDATA)> <br/> <! ELEMENT Price (# PCDATA)> </tbody> </p> <p> This code shows that the element catalog contains multiple CD sub-elements, and the child element cd contains the Title in turn, artist, Year, Country, Company, and Price sub-elements. their content is defined as text (character, number, text ). (Note: For more information about the syntax, see the content of DTD in the previous chapter.) </p> <p> Step 2: create an XML document </p> <tbody> Reference content: <br/> <p> <? Xml version = "1.0"?> <Br/> <CATALOG> <br/> <CD> <br/> <TITLE> Empire Burlesque
Bob Dylan
USA
Columbia
10.90
1985
Hide your heart
Bonnie Tylor
UK
CBS Records
9.90
1988
Greatest Hits
Dolly Parton
USA
RCA
9.90
1982
Still got the blues
Gary More
UK
Virgin redords
10.20
1990
Eros
Eros Ramazzotti
EU
BMG
9.90
1997
The above code first uses The declaration statement indicates that this is an XML document and its structure complies with the XML 1.0 standard. Then there is the document content, and the structure tree is very clear:
Reference content is as follows:
......
......
A total of five groups of data are defined. We save the above code as a cd. xml file for calling.
Step 3: Create an HTML file
1. import XML data
We know that currently, only Microsoft IE5.0 and later browsers support XML in popular browsers. IE supports XML insertion through the object objects in HTML, and imports data through the XMLDocument. load () method of js. Let's look at the code:
Reference content is as follows:
CLASSID = "clsid: 550dda30-0541-11d2-9ca9-0060b0ec3d39" ID = "xmldso">
Define an object named xmldso. Then introduce xml data with js in the head area:
Reference content is as follows: