The combination of XML and HTML (top) _xml/rss

Source: Internet
Author: User
Tags unique id

Beijing posts and telecommunications Zhang Jian

 

Limitations of XML

Currently, the content data for many Web sites are stored in a database or data file. For Web program developers, if you want to extract useful information from a database, the traditional approach is to write scripts on the server side (such as VBScript, JavaScript, CGI, ASP, Perl, and so on) and get records by executing SQL queries against the database. The query results are then organized into HTML pages and returned to the client, where the user observes the final result using a browser.

In order to improve the flexibility and scalability of the system services, so that the scope of the service object is wider, many commercial web sites as far as possible to the business rules, raw data and representations as separate services provided separately. The way HTML aggregates data in the display is clearly not in line with this demand. Therefore, storing the raw data in an XML document and using the style sheet file to display the content is the advantage that XML technology is suitable for the electronic commerce. But in essence, XSL technology is not data-oriented, it is a format conversion technology, in the display means and methods are far less rich than HTML. For programmers, an ideal solution is to combine HTML and XML two technologies to complement each other, so that real raw data can maintain its original meaning and structure while still taking full advantage of the ever-changing display skills of HTML. XML data island is the product of this technology fusion, it uses <XML> tag to embed XML data directly into the HTML page, thus achieving the complementary advantages of the two.

processing method of data island in IE

To be able to handle this HTML page with embedded XML code, Internet Explorer 4.0 (IE 4.0) introduces the DSO (data source Objects, DataSource object) technology, implemented using Java applets.

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 example above, the code attribute indicates the DSO Java applet, and the Mayscript property guarantees that the client script can handle the data object, and the Param tag indicates the location of the XML document.

The limitation of using Java is that you can only describe the URL of the XML in an HTML document, but not the XML tag directly, and there is a gap between the real data island scenario. Microsoft has expanded the DSO technology in Internet Explorer 5.0 (IE 5.0) to break through the limitations of the past, so that HTML and XML are truly fused together. Direct use <XML> tags are supported in HTML pages.

For example:

<HTML>

<xml id= "Xmldso" >

<?xml version= "1.0"?>

Some XML ...

</XML>

As long as you guarantee that each data island ID is unique, you can embed the data island wherever necessary in the page, and these DSO are independent of each other.

In addition to this direct embedding method in the example above, you can also use external references to link data islands.

For example:

<xml id= "Xmldso" src= "Myxml.xml" >

</XML>

In this way, the Java applet is the choice that programmers should consider only if the company's client object continues to use IE 4.0 and to address this part of the customer's compatibility issues.

In the DSO technology implemented by IE 5.0, if the data is the result of querying the database through the SQL language, it is stored in the ADO (ActiveX Data Objects) recordset. The server sends this ActiveX control (usually an ADO recordset) to the client, which is further processed by the client script. In fact, IE 5.0 is the XML data island as a special ADO recordset processing.

data binding FOR XML

1. Mapping of ADO recordset

Each primary element in the XML is mapped to a record in the ADO recordset, and the child elements are mapped to fields (also called fields) in the recordset.

For example, there are XML data islands books.xml 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 point, the mapped ADO recordset is:

Title ISBN

Straight Talk about Computers 72-80088-005

Gourmet Microwave 72-80081-082

2. Binding to HTML elements

After you embed the data island in an HTML document, you can bind the XML data island to the HTML element. Each DSO entry (that is, the data island) has a unique ID number. You can associate HTML elements with data islands by first setting the DATASRC attribute in the HTML element to the appropriate ID. The extracted XML element is then determined by setting the Datafld property value.

For example, the code that binds 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 are bound to the XML data island. Currently, the elements that support this DSO binding mechanism are as follows:

A, APPLET, BUTTON, DIV, FRAME, IFRAME, IMG, INPUT (here types are: CHECKBOX, HIDDEN, label, PASSWORD, Radio and text), label, MARQUEE, SELECT, SPAN, table, and TEXTAREA.

3. Explicit XML data in tabular format

If you bind the XML data to the table element, you can automatically display it as a multiple-row table Form.

For example, the code that binds the 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 Datasrc property in the table element is set to #xmldso to bind the two. The table is divided into two parts: the table Head (THEAD) and the table body (tbody). Each <book> element is displayed as a row table, and each column shows which data is specified by the Datafld property in the DIV element.

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.