Resolving user interface problems with XML data Islands-3

Source: Internet
Author: User
Tags date format end interface sql query reference access database
xml| Solution | data | Problem Save the database's table data to a file

I have promised to show you how to avoid the steps of reading a database and concatenating it into an XML string each time a request is made. The answer is to save the database's table data to a file, which has several benefits. It is faster to read a file than to query the database and format the recordset into XML. Doing so can also simplify your HTML files because you only need to include references to XML in HTML. Finally, this makes the data transparent to the client. If you send an XML tag in Listing 1, the user can see the data through IE's "view/source file". With a file reference, the user sees only the reference marker, not the data.

As long as your database records are not immutable, you will have to query the database when the data changes. For example, you can write a trigger in SQL Server that updates the date and time in the LastChanged table when the "Location" Table changes (Listing 3). For each request, you can compare
Location the date and time of the table with the XML file that saved the data. The Access database used in this article does not support triggers, but you can write code to implement the ability to update the "lastchanged" table when the "Location" table changes. You can also regenerate files every once in a while, such as a day or one hours.

Write an XML file to your hard disk with Scripting.FileSystemObject and Scripting.TextStream objects. In order to be able to write XML files, you must give IUSR_machinename an anonymous account with sufficient permissions to open, read, write, and delete files (if you are using an NTFS-formatted partition hard disk). If you only want to use XML data to recreate a recordset on the client, you can save the recordset to your hard disk by using the adPersistXML method. If you do this, you must be aware that ADO saves the recordset in an optimized format in order to re-establish the recordset from the XML data. This generates XML for XSL query statements that are
It is not convenient to be beautiful:

Dim FS

Dim TS

Dim afilename

Afilename = Server.MapPath _ ("/xmldataislands") & _ "\locations.xml"

Set fs = Server.CreateObject _ ("Scripting.FileSystemObject")

Set ts = fs. OpenTextFile _ (Afilename, ForWriting)

Ts. Write s

Now, when you receive a request, look at the date and time in the "lastchanged" table:

Dim SQL

Dim R

Dim Conn

Dim tablemodifydate

Set Conn = Server.CreateObject _ ("ADODB.") Connection ")

Conn.mode = adModeRead

Conn.Open "DSN=CHEAPPC; Uid=sa; Pwd= "

SQL = "Select" & _ "lastchanged.lastchanged" & _ "from Locations WHERE" & _ "Tablename= ' Locations '"

Set R = Conn.execute (Sql,,adcmdtext)

Tablemodifydate = R ("lastchanged")

Next, compare the date and time of the XML file with the Tablemodifydate by fetching a file object and view its Filecreatedon property value:

Dim fs

Dim afile

Dim rewritefile

Rewritefile=false

Set fs = Server.CreateObject _ ("Scripting.FileSystemObject")

If Fs. FileExists (Afilename) Then

Set afile = fs. GetFile (Afilename)

If afile.datecreated < _locationsmodifieddate Then

Rewritefile=true

End If

Else

Rewritefile=true

End If
If the XML file does not exist or needs to be updated, you must write the file (Listing 4). This will retrieve the data from the database and format it into XML, but you simply overwrite the old XML file without having to send the XML to the browser. Now in your HTML file, you just need to reference the XML file. When your XML file does not need to be updated, your server skips the reading and formatting of the data and simply reads the XML data to the browser. On the whole, reading XML data saves your server a lot of processing power and makes your pages more efficient.


Source code can be downloaded from http://www.yesky.com/34670816/xmldaima.zip


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.