Zhang Jian, Beijing University of Posts and Telecommunications
Limitations of XML
Currently, the content data of many Web sites are stored in databases or data files. For Web program developers, if they want to extract useful information from the database, the traditional method is to write scripts on the server side (such as VBScript, JavaScript, CGI, ASP, Perl, etc.) and execute the database The SQL query obtains the relevant records, and then organizes the query results into an HTML page and returns it to the client. The user uses the browser to observe the final results.
In order to improve the flexibility and scalability of system services and enable a wider range of service targets, many commercial websites try their best to provide business rules, original data and presentation forms as independent services. HTML's way of embedding data in display obviously does not meet this need. Therefore, storing original data in XML documents and using style sheets to display content are the advantages of XML technology suitable for e-commerce. But in essence, XSL technology is not oriented to data display. It is a format conversion technology that is far less rich than HTML in terms of display means and methods. For programmers, a more ideal solution is to combine the two technologies of HTML and XML to complement each other's advantages, so that the real original data can maintain its original meaning and structure while making full use of the ever-changing display of HTML. Skill. XML Data Island is the product of this technology fusion. It uses the <XML> tag to embed XML data directly into HTML pages, thus realizing the complementary advantages of the two.
How to handle data islands in IE
In order to be able to handle this kind of HTML page with embedded XML code, Internet Explorer 4.0 (hereinafter referred to as IE 4.0) introduced DSO (Data Source Objects, data source object) technology, which is implemented with Java Applet.
For example:
<APPLET CODE="com.ms.xml.dso.XMLDSO.class"
ID="xmldso" WIDTH=0 HEIGHT=0 MAYSCRIPT=TRUE>
<PARAM NAME="URL" VALUE="myXML.xml">
< /APPLET>
In the above example, the CODE attribute specifies the DSO Java applet, the MAYSCRIPT attribute ensures that the client script can process the data object, and the PARAM tag specifies the location of the XML document.
The limitation of using Java is that it can only describe the URL address of XML in the HTML document, but cannot directly embed the XML tag into it. This is still far behind the real data island solution. Microsoft has expanded DSO technology in Internet Explorer 5.0 (hereinafter referred to as IE 5.0), breaking through previous limitations and truly integrating HTML and XML. HTML pages support direct use of <XML> tags.
For example:
<HTML>
<XML ID="xmldso">
<?xml version="1.0"?>
some XML...
</XML>
As long as the ID of each data island is unique, it can be included in the page Data islands are embedded wherever necessary, and these DSOs are independent of each other.
In addition to the direct embedding method in the above example, you can also use external references to link data islands.
For example:
<XML ID="xmldso" SRC="myXML.xml">
</XML>
In this way, only when the company's customer objects continue to use IE 4.0, and in order to solve the compatibility issues of these customers, the Java Applet is Options for programmers to consider.
In the DSO technology implemented by IE 5.0, if the data is the result of querying the database through SQL language, then they are stored in the ADO (ActiveX Data Objects) record set. The server sends this ActiveX control (usually an ADO recordset) to the client, where the client script program performs further processing. In fact, IE 5.0 handles XML data islands as a special ADO record set.
XML data binding
1. ADO recordset mapping
Each main element in XML is mapped to a record in the ADO recordset, and the sub-elements are correspondingly mapped to fields (also called domains) in the recordset.
For example, the XML data island books.xml exists as follows:
<XML ID="xmldso">
<?xml version="1.0"?>
<booklist>
<book>
<title>Straight Talk About Computers</title>
<isbn>72 -80088-005</isbn>
</book>
<book>
<title> Gourmet Microwave </title>
<isbn>72-80081-082</isbn>
</book>
</booklist>
</XML>
At this time , the mapped ADO record set is:
title isbn
Straight Talk About Computers 72-80088-005
Gourmet Microwave 72-80081-082
2. Binding to HTML elements
After embedding data islands in an HTML document, you can bind XML data islands to HTML elements. Each DSO entry (ie, data island) has a unique ID number. First, set the DATASRC attribute in the HTML element to the corresponding ID to associate the HTML element with the data island. Then determine the extracted XML element by setting the DATAFLD attribute value.
For example, the code bound to the DIV element is as follows:
<DIV ID=title DATASRC=#xmldso DATAFLD="title"></DIV>
<DIV ID=price DATASRC=#xmldso DATAFLD="isbn"></DIV>
Note : Not all HTML elements can be bound to XML data islands. Currently, the elements that support this DSO binding mechanism are as follows:
A. APPLET, BUTTON, DIV, FRAME, IFRAME, IMG, INPUT (the types here are: CHECKBOX, HIDDEN, LABEL, PASSWORD, RADIO and TEXT), LABEL, MARQUEE , SELECT, SPAN, TABLE and TEXTAREA.
3. Explicit XML data in a tabular format
If you bind the XML data to the TABLE element, it can be automatically displayed in a multi-row tabular format.
For example, the code that binds XML data to the TABLE element is as follows:
<TABLE BORDER=1 DATASRC="#xmldso">
<THEAD>
<TR><TH>Title</TH>
<TH>ISBN</TH></TR >
</THEAD>
<TBODY>
<TR><TD><DIV DATAFLD="title"></DIV></TD>
<TD><DIV DATAFLD="isbn">
</DIV></TD>< /TR>
</TBODY>
</TABLE>
In this way, the two are bound by setting the DATASRC attribute in the TABLE element to #xmldso. The table is divided into two parts: header (THEAD) and table body (TBODY). Each <book> element will be displayed as a row of tables. Which data is displayed in each column is specified by the DATAFLD attribute in the DIV element.