Using ASP to make Access remote interface

Source: Internet
Author: User
Tags chr mdb database uuid xmlns xsl xslt
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 (&AMP;CHR) &AMP;CHR (9)
xslt= "<?xml version=" "1.0" "?>" & Chr (a) &AMP;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&AMP;CHR (9) _
& "<xsl:element name=" "xml" ">" & STR&AMP;CHR (9) &AMP;CHR (9) _
& "<xsl:for-each select=" "/xml/rs:data/z:row" ">" & STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "<xsl:element name=" "Row" ">" & STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "<xsl:for-each select=" "@*" ">" & STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "<xsl:element name=" "{Name ()}" ">" & STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "<xsl:value-of select=" "." /> "& STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "</xsl:element>" & STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "</xsl:for-each>" & STR&AMP;CHR (9) &AMP;CHR (9) &AMP;CHR (9) _
& "</xsl:element>" & STR&AMP;CHR (9) &AMP;CHR (9) _
& "</xsl:for-each>" & STR&AMP;CHR (9) _
& "</xsl:element>" & Str_
& "</xsl:template>" & Chr (+) &AMP;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>




Related Article

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.