Home  >  Article  >  Web Front-end  >  Complementary advantages between HTML and XML (Part 1)

Complementary advantages between HTML and XML (Part 1)

零下一度
零下一度Original
2017-05-02 15:08:091779browse

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 relevant records, and then organizes the query results into HTML pages and returns them 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 d9612f61437e20b5df317e4aa7a27021 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 objects) Technology, implemented using 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 user-side 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 d9612f61437e20b5df317e4aa7a27021 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, you can embed data islands wherever necessary in the page, 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 problems of these customers, Java Applet is what programmers need. Options 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

Every main element in XML is mapped to a record in the ADO recordset, and the sub-elements are correspondingly mapped to fields in the recordset (also called domains).

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 the data island in the HTML document, you can bind the XML data island to the HTML element. 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 p element is as follows:

<p ID=title DATASRC=#xmldso DATAFLD=“title”></p>

<p ID=PRice DATASRC=#xmldso DATAFLD=“isbn”></p>

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, p, 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 tabular format

If XML data is bound to the TABLE element, it can be automatically displayed in a multi-row tabular format.

For example, the code for binding XML data to TABLE elements is as follows:

<TABLE BORDER=1 DATASRC=“#xmldso”>

<THEAD>

<TR><TH>Title</TH>

<TH>ISBN</TH></TR>

</THEAD>

<TBODY>

<TR><TD><p DATAFLD=“title”></p></TD>

<TD><p DATAFLD=“isbn”>

</p></TD></TR>

</TBODY>
1
</TABLE>


这样,通过将TABLE元素中的DATASRC属性设定为#xmldso,把两者绑定起来。表格内部分为表头(THEAD)和表体(TBODY)两部分。每一个463aef0d2da08708f472268a99530dbe元素都会显示为一行表格,具体每一栏显示哪一项数据,则由p元素中的DATAFLD属性指定。                        

The above is the detailed content of Complementary advantages between HTML and XML (Part 1). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn