Before seeing many netizens asked, oneself have two servers, how these two server's MDB database data exchange. Today, we made a remote interface to return the data in the MDB in XML form. The main idea is to populate the XML DOM with the Save method of the Recordset object, but this method produces XML that is not concise enough to produce XML that contains schema information that describes what nodes and attributes are allowed in the XML and what data types are used , and the data nodes also add namespaces. Schema information may be useful where data validation is required or more complex processing, but, in most cases, we are using thin clients and we do not need schema information. We can use XSLT to isolate the information we want, and remove the unwanted information.
The code is as follows:
<%
' Generate XSL Style
str = chr (&CHR) &CHR (9)
xslt= "<?xml version=" "1.0" "?>" & Chr (a) &CHR (Ten) & "<xsl:stylesheet version=" "1.0" "" _
& "Xmlns:xsl=" "Http://www.w3.org/1999/XSL/Transform"""_
& "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" ">" & str_
& "<xsl:output omit-xml-declaration=" "Yes" "/>" &str_
& "<xsl:template match="/">" & STR&CHR (9) _
& "<xsl:element name=" "xml" ">" & STR&CHR (9) &CHR (9) _
& "<xsl:for-each select=" "/xml/rs:data/z:row" ">" & STR&CHR (9) &CHR (9) &CHR (9) _
& "<xsl:element name=" "Row" ">" & STR&CHR (9) &CHR (9) &CHR (9) &CHR (9) _
& "<xsl:for-each select=" "@*" ">" & STR&CHR (9) &CHR (9) &CHR (9) &CHR (9) &CHR (9) _
& "<xsl:element name=" "{Name ()}" ">" & STR&CHR (9) &CHR (9) &CHR (9) &CHR (9) &CHR (9) &CHR (9) _
& "<xsl:value-of select=" "." /> "& STR&CHR (9) &CHR (9) &CHR (9) &CHR (9) &CHR (9) _
& "</xsl:element>" & STR&CHR (9) &CHR (9) &CHR (9) &CHR (9) _
& "</xsl:for-each>" & STR&CHR (9) &CHR (9) &CHR (9) _
& "</xsl:element>" & STR&CHR (9) &CHR (9) _
& "</xsl:for-each>" & STR&CHR (9) _
& "</xsl:element>" & Str_
& "</xsl:template>" & Chr (+) &CHR (10) _
& "</xsl:stylesheet>"
Read database
CurDir = Server.MapPath ("Data.mdb")
Set Conn=server.createobject ("Adodb.connection")
Conn. Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & CurDir
Set Rs=conn. Execute ("SELECT * from admins")
Dim objxmldom
Set objxmldom = Server.CreateObject ("MSXML2. domdocument.3.0 ")
" save a Recordset object to the DOM
Rs.save objxmldom, 1
Set rs = Nothing
Dim strcleanxml, Objxmldom_ XSLT
Set objxmldom_xslt = CreateObject ("MSXML2. DOMDocument ")
Objxmldom_xslt.loadxml (XSLT)
' formats data with XSL
strcleanxml = Objxmldom.transformnode (objxmldom_ XSLT)
Set objxmldom = Nothing
Set objxmldom_xslt = Nothing
' output data
Response.Write Strcleanxml
%>
Because XML is cross-platform, either ASP or JSP or the client can get the data through the interface, and then display the data in its own style. For example, at the client we can use JavaScript operation XMLHTTP to for an MDB on www.xxxx.com :
<script language= "JavaScript" >
function req () {
var xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
xmlHTTP. Open ("Get", "http://www.xxxx.com/mdb_inerface.asp", false);
' mdb_interface.asp is both an MDB interface file placed on the www.xxxx.com
xmlHTTP. Send ();
alert (Xmlhttp.responsetext);
}
</script>
</HEAD>
<body>
<input type= "button" value= "Get"/></br>