Implement the display of the database using XML technology (1)

zhaozj2021-02-16  45

Overview: This document describes how to use it

Xml

Language implementation

Web

On the page

OWC

Methods of displaying data in the database. due to

Xml

The data can span the firewall, so this method can be implemented

Internet

The data is displayed.

In web-based database analysis applications, there is often a display of the table and charts of the data using the OWC control to integrate data. General applications often use OWC to directly connect to the database, which will expose the database connection password to the client, and reduce the security of the database. This article describes how to use XML as an OWC and database data exchange media to avoid this unsafe danger caused by the database. At the same time, this can also bring other benefits, for example, reduce the number of interactions between the browser and the web server and the database, thereby accelerating the response speed of the sorting and other operations, and reduces the load of the server.

First, get XML data

There are many ways to convert data in the database to XML format. This document is not more to this. From the perspective of performance, versatility, here we use ADO direct serialization (persistent PERSIST) data, the code is as follows:

<%

DIM STRCONNNNNNN

StrConn = "provider = SQLOLEDB.1; PERSIST security info = false; user id = sa; initial catalog = test; data source = jlwz"

'---------- Read the data ----------------

DIM CONN, RS

Set conn = server.createObject ("adoDb.connection")

SET RS = Server.createObject ("AdoDb.Recordset")

Conn.open straconn

Rs.open "Select Stat_Date, Call_Num, Call_Fe from Callstat", Conn

'Translate ADO to XML DOM

Const adpersistxml = 1

DIM Objxmldom

Set objxmldom = server.createObject ("msxml2.domdocument.3.0")

rs.save objxmldom, AdpersistXML

SET RS = Nothing

%>

The XML obtained in this way is not simple enough, including SCHEMA information.

Although this form of XML data can be directly adopted for the DataSourceControl control in OWC, it is considering the efficiency of the data from the server to the client, we use XSLT to transform this XML data. To this end, write the following Clean.xsl file:

XMLns: s = "UUID: BDC6E3F0-6DA3-11D1-A2A3-00AA00C14882"

XMLns: DT = "UUID: C2F41010-65B3-11D1-A29F-00Aa00C14882"

XMLns: RS = "URN: Schemas-Microsoft-Com: Rowset" XMLns: z = "# RowsetSchema">

Then, in GetData.asp, the front XML data is converted by the following code:

'Clean up XML data with XSLT

DIM STRCLEANXML, OBJXSLT

Set objxslt = server.createObject ("msxml2.domdocument")

Objxslt.Load (Server.Mappath ("Clean.xsl"))

StrcleanXML = ObjxmlDom.TransformNode (objxslt)

At this time, you get the string of the relatively simple XML structure we want, you can simply send its response.write to the client:

2003-06-01

100

200

2003-07-01

200

400

. . .

转载请注明原文地址:https://www.9cbs.com/read-25173.html

New Post(0)