明輝手游網(wǎng)中心:是一個免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

ADO數(shù)據(jù)與XML數(shù)據(jù)間的轉(zhuǎn)換的類(ASP完成)

[摘要]當(dāng)對現(xiàn)有數(shù)據(jù)庫的數(shù)據(jù)進(jìn)行分析時,經(jīng)常需要對某一部分的數(shù)據(jù)進(jìn)行分析.此時,使用1.SQL查詢分析器? 但其往往不直觀,查找某個關(guān)鍵字又需要重新執(zhí)行新的SQL.2.SQLXML模板? 但又不一定有權(quán)限建立新的虛擬目錄,且某些SQL語句SQLXML模板不支持?jǐn)?shù)據(jù)拆離時也有相似問題。尤其當(dāng)不同網(wǎng)絡(luò),不同環(huán)...
當(dāng)對現(xiàn)有數(shù)據(jù)庫的數(shù)據(jù)進(jìn)行分析時,經(jīng)常需要對某一部分的數(shù)據(jù)進(jìn)行分析.此時,使用
1.SQL查詢分析器?
 但其往往不直觀,查找某個關(guān)鍵字又需要重新執(zhí)行新的SQL.
2.SQLXML模板?
 但又不一定有權(quán)限建立新的虛擬目錄,且某些SQL語句SQLXML模板不支持
數(shù)據(jù)拆離時也有相似問題。
尤其當(dāng)不同網(wǎng)絡(luò),不同環(huán)境,需要重新導(dǎo)入數(shù)據(jù),進(jìn)行分析或拆離,困難尤為明顯。
能不能有一種方法,可以將數(shù)據(jù)脫離于數(shù)據(jù)庫進(jìn)行分析,需要時再導(dǎo)入到數(shù)據(jù)庫中?
XML是個很好的選擇!
ADO本身支持?jǐn)?shù)據(jù)到XML的轉(zhuǎn)換,只需要對其格式進(jìn)行解析,成為自己的XML文件通用格式,就可以進(jìn)行本地分析
而對通用XML格式進(jìn)行數(shù)據(jù)庫映射,就可完成數(shù)據(jù)重新導(dǎo)入數(shù)據(jù)庫的工作.
下面是一個ADO數(shù)據(jù)(表的基本數(shù)據(jù))與XML數(shù)據(jù)間的相互轉(zhuǎn)換的類(ASP實現(xiàn)),初步完成表數(shù)據(jù)的導(dǎo)入、導(dǎo)出。
通用表間關(guān)系映射(通過XSD描述),考慮之中,希望各位賜教指點,不勝感激.
一個調(diào)用類的例子:
example.asp
<!--#include file="transformData.asp"-->
<%
Dim aSQL(1,1)
Dim oXMLData
'====== 連接數(shù)據(jù)庫過程 ======
'獲得數(shù)據(jù)庫連接對象 oDbConn
'====== 連接數(shù)據(jù)庫過程 ======
aSQL(0,0) = "PubLable"
aSQL(0,1) = "Select * from PubLabel where cLabelName like '%abc%' Order by nLabelID"
aSQL(1,0) = "PubUser"
aSQL(1,1) = "Select * from PubUser where cUserName like '%abc%' Order by nUserID"
set oXMLData = New TransformData
Call Export()&nbsp;
'Call Import()&nbsp;
set oXMLData = nothing

'&nbsp;// 當(dāng)對象屬性有默認(rèn)值(default())時,可以不用在賦值
Sub Export()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;&nbsp; // 導(dǎo)出數(shù)據(jù)
&nbsp;oXMLData.aSQlData&nbsp;&nbsp;= aSQL&nbsp;&nbsp;&nbsp;
&nbsp;' 必須&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2維SQL語句數(shù)組
&nbsp;
&nbsp;oXMLData.bIsSave&nbsp;&nbsp;= 1&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;' default(1)&nbsp;&nbsp;&nbsp;&nbsp;是否保存為XML文件
&nbsp;
&nbsp;oXMLData.bIsOutput&nbsp;&nbsp;= 1&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;' default(0)&nbsp;&nbsp;&nbsp;&nbsp;是否顯示XML數(shù)據(jù)
&nbsp;
&nbsp;oXMLData.sSaveFileName&nbsp;= "Data.xml"&nbsp;
&nbsp;' default(當(dāng)前時間加隨機(jī)數(shù))&nbsp;如果保存XML數(shù)據(jù),XML文件名稱
&nbsp;
&nbsp;oXMLData.sSaveFilePath&nbsp;= ""&nbsp;&nbsp;&nbsp;
&nbsp;' default("")&nbsp;&nbsp;&nbsp;&nbsp;如果保存XML數(shù)據(jù),XML文件路徑(相對路徑)
&nbsp;
&nbsp;oXMLData.sEncoding&nbsp;&nbsp;= "gb2312"&nbsp;&nbsp;
&nbsp;' default("gb2312")&nbsp;&nbsp;&nbsp;XML文件編碼類型
&nbsp;oXMLData.Export (oDbConn)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;' // 導(dǎo)出數(shù)據(jù)過程
&nbsp;IF (oXMLData.nErrCode<>0) Then&nbsp;&nbsp;' nErrCode(錯誤代碼)為0,運(yùn)行成功
&nbsp;&nbsp;Response.Write oXMLData.GetErrExegesis(oXMLData.nErrCode)&nbsp;
&nbsp;&nbsp;'nErrCode(錯誤代碼),通過方法GetErrExegesis() 獲得注釋
&nbsp;End IF
End Sub
Sub Import()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;&nbsp; // 導(dǎo)入數(shù)據(jù)
&nbsp;oXMLData.sXMLFile&nbsp;&nbsp;= "Data.xml"&nbsp;' 必須&nbsp;&nbsp;數(shù)據(jù)源XML文件(包含相對路徑)&nbsp;
&nbsp;oXMLData.sVacancyCols&nbsp;= "nLabelID"&nbsp;' 必須&nbsp;&nbsp;指定某些字段的值可以不導(dǎo)入(屏蔽字段)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' 格式&nbsp; &nbsp;"nID,dDate"&nbsp; (以‘,’分隔字段)
&nbsp;oXMLData.Import (oDbConn)
&nbsp;IF (oXMLData.nErrCode=0) Then
&nbsp;&nbsp;Response.Write "數(shù)據(jù)導(dǎo)入成功!"
&nbsp;Else
&nbsp;&nbsp;Response.Write oXMLData.GetErrExegesis(oXMLData.nErrCode)
&nbsp;End IF
&nbsp;
End Sub
%>
&nbsp;
類的代碼:
TransformData.asp
<%
Class TransformData
'*****************************************************
'&nbsp;Copyright (c) 2003
'&nbsp;創(chuàng) 建 人&nbsp;:&nbsp;moonpiazza
'&nbsp;日&nbsp;&nbsp;&nbsp; 期&nbsp;:&nbsp;2003.5.21
'&nbsp;描&nbsp;&nbsp;&nbsp; 述&nbsp;:&nbsp;ADO數(shù)據(jù)與XML數(shù)據(jù)間的轉(zhuǎn)換(ASP實現(xiàn))
'&nbsp;版&nbsp;&nbsp;&nbsp; 本&nbsp;:&nbsp;1.0
'&nbsp;功&nbsp;&nbsp;&nbsp; 能&nbsp;:&nbsp;&nbsp; ADO數(shù)據(jù)(表的基本數(shù)據(jù))與XML數(shù)據(jù)間的相互轉(zhuǎn)換
'&nbsp;待 改 進(jìn)&nbsp;:&nbsp;表間數(shù)據(jù)的關(guān)聯(lián)性(通用),數(shù)據(jù)量大時速度問題
'
'&nbsp;版&nbsp;權(quán)&nbsp;:&nbsp;歡迎改進(jìn),翻版不究&nbsp;&nbsp;:_)
'
'*****************************************************

'*****************************************************
'&nbsp;公共方法:&nbsp;Export, Import, GetErrExegesis
'*****************************************************
'============================= 公共變量&nbsp; End =============================
Private m_oXMLDOM
Private m_oXSLDOM
'============================= 公共變量 Begin =============================
&nbsp;
'============================= 錯誤代碼定義 Begin =============================
Private m_nErrCode_NotArray&nbsp;
Private m_nErrCode_XMLDOM&nbsp;
Private m_nErrCode_ReadData&nbsp;
Private m_nErrCode_WriteData
Private m_nErrCode_Save&nbsp;&nbsp;
Private m_nErrCode_EnsFile&nbsp;
Private m_nErrCode_ErrFile&nbsp;
'============================= 錯誤代碼定義&nbsp; End =============================
&nbsp;
'============================= 屬性定義 Begin =============================
Private m_aSQlData&nbsp;&nbsp;
Private m_bIsSave
Private m_bIsOutput
Private m_sSaveFileName
Private m_sSaveFilePath
Private m_sXMLFile
Private m_sVacancyCols
Private m_nErrCode
Private m_sEncoding
Private m_sImportSQL
'*****************************************************
'&nbsp;屬性:&nbsp;aSQlData
'&nbsp;狀態(tài):&nbsp;可寫
'&nbsp;類型:&nbsp;2維數(shù)組&nbsp;
'&nbsp;描述:&nbsp;SQL語句數(shù)組,1維是表名稱,2維是相應(yīng)SQL語句
'*****************************************************
Public Property Let aSQlData(ByRef p_aSQlData)
&nbsp;m_aSQlData&nbsp;= p_aSQlData
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;bIsSave
'&nbsp;狀態(tài):&nbsp;可寫
'&nbsp;類型:&nbsp;數(shù)字(0,1)&nbsp;default(1)
'&nbsp;描述:&nbsp;導(dǎo)出數(shù)據(jù)時,是否保存為XML文件&nbsp;
'*****************************************************
Public Property Let bIsSave(ByRef p_bIsSave)
&nbsp;m_bIsSave&nbsp;= Cint(p_bIsSave)
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;bIsOutput
'&nbsp;狀態(tài):&nbsp;可寫
'&nbsp;類型:&nbsp;數(shù)字(0,1)&nbsp;default(0)
'&nbsp;描述:&nbsp;導(dǎo)出數(shù)據(jù)時,是否顯示XML數(shù)據(jù)
'*****************************************************
Public Property Let bIsOutput(ByRef p_bIsOutput)
&nbsp;m_bIsOutput&nbsp;= Cint(p_bIsOutput)
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;sSaveFileName
'&nbsp;狀態(tài):&nbsp;可寫,可讀
'&nbsp;類型:&nbsp;字符串&nbsp;default(GetRndFileName())
'&nbsp;描述:&nbsp;導(dǎo)出數(shù)據(jù)時,如果保存XML數(shù)據(jù),XML文件名稱
'*****************************************************
Public Property Let sSaveFileName(ByRef p_sSaveFileName)
&nbsp;m_sSaveFileName&nbsp;= p_sSaveFileName
End Property
Public Property Get sSaveFileName()&nbsp;
&nbsp;sSaveFileName&nbsp;= m_sSaveFileName
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;sSaveFilePath
'&nbsp;狀態(tài):&nbsp;可寫,可讀
'&nbsp;類型:&nbsp;字符串&nbsp;default("")
'&nbsp;描述:&nbsp;導(dǎo)出數(shù)據(jù)時,如果保存XML數(shù)據(jù),XML文件路徑(相對路徑)
'*****************************************************
Public Property Let sSaveFilePath(ByRef p_sSaveFilePath)
&nbsp;m_sSaveFilePath&nbsp;= p_sSaveFilePath
End Property
Public Property Get sSaveFilePath()&nbsp;
&nbsp;sSaveFilePath&nbsp;= m_sSaveFilePath
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;sXMLFile
'&nbsp;狀態(tài):&nbsp;可寫
'&nbsp;類型:&nbsp;字符串&nbsp;
'&nbsp;描述:&nbsp;導(dǎo)入數(shù)據(jù)時,數(shù)據(jù)源XML文件(包含相對路徑)&nbsp;
'*****************************************************
Public Property Let sXMLFile(ByRef p_sXMLFile)
&nbsp;m_sXMLFile&nbsp;= p_sXMLFile
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;sVacancyCols
'&nbsp;狀態(tài):&nbsp;可寫
'&nbsp;類型:&nbsp;字符串&nbsp;default("")
'&nbsp;&nbsp;&nbsp;格式&nbsp; &nbsp;"nID,dDate"&nbsp; (以‘,’分隔字段)
'&nbsp;描述:&nbsp;導(dǎo)入數(shù)據(jù)時,指定某些字段的值可以不導(dǎo)入(屏蔽字段)
'*****************************************************
Public Property Let sVacancyCols(ByRef p_sVacancyCols)
&nbsp;m_sVacancyCols&nbsp;= "," & p_sVacancyCols & ","
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;nErrCode
'&nbsp;狀態(tài):&nbsp;可讀
'&nbsp;類型:&nbsp;數(shù)字 &nbsp;default(0)
'&nbsp;描述:&nbsp;錯誤代碼,可通過方法GetErrExegesis(ByRef p_nErrCode) 獲得注釋
'*****************************************************
Public Property Get nErrCode()&nbsp;
&nbsp;nErrCode&nbsp;= m_nErrCode
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;sEncoding
'&nbsp;狀態(tài):&nbsp;可寫
'&nbsp;類型:&nbsp;字符串&nbsp;default("gb2312")
'&nbsp;描述:&nbsp;XML文件編碼類型
'*****************************************************
Public Property Let sEncoding(ByRef p_sEncoding)
&nbsp;m_sEncoding&nbsp;= p_sEncoding
End Property

'*****************************************************
'&nbsp;屬性:&nbsp;sImportSQL
'&nbsp;狀態(tài):&nbsp;可讀
'&nbsp;類型:&nbsp;字符串&nbsp;default("gb2312")
'&nbsp;描述:&nbsp;導(dǎo)入數(shù)據(jù)時,生成的SQL語句
'*****************************************************
Public Property Get sImportSQL()&nbsp;
&nbsp;sImportSQL&nbsp;= m_sImportSQL
End Property
'============================= 屬性定義 End =============================
&nbsp;
'*****************************************************
'&nbsp;初始化類
'*****************************************************
Private Sub Class_Initialize()
&nbsp;Server.ScriptTimeout = 1000
&nbsp;m_nErrCode_NotErr&nbsp;= 0
&nbsp;m_nErrCode_NotArray&nbsp;= 1
&nbsp;m_nErrCode_XMLDOM&nbsp;= 2
&nbsp;m_nErrCode_ReadData&nbsp;= 3
&nbsp;m_nErrCode_WriteData= 4
&nbsp;m_nErrCode_Save&nbsp;&nbsp;= 5
&nbsp;m_nErrCode_EnsFile&nbsp;= 6
&nbsp;m_nErrCode_ErrFile&nbsp;= 7

&nbsp;m_bIsSave&nbsp;&nbsp;&nbsp;= 1
&nbsp;m_bIsOutput&nbsp;&nbsp;&nbsp;= 0
&nbsp;m_sSaveFilePath&nbsp;&nbsp;= ""
&nbsp;m_sSaveFileName&nbsp;&nbsp;= ""
&nbsp;m_sXMLFile&nbsp;&nbsp;&nbsp;= ""
&nbsp;m_sVacancyCols&nbsp;&nbsp;= ""
&nbsp;m_nErrCode&nbsp;&nbsp;&nbsp;= m_nErrCode_NotErr
&nbsp;m_sEncoding&nbsp;&nbsp;&nbsp;= "gb2312"
End Sub

'*****************************************************
'&nbsp;注銷類
'*****************************************************
Private Sub Class_Terminate()
&nbsp;&nbsp;Set m_oXMLDOM&nbsp;= Nothing
&nbsp; Set m_oXSLDOM&nbsp;= Nothing&nbsp;
End Sub

'============================= 數(shù)據(jù)導(dǎo)出 Begin =============================
'*****************************************************
'&nbsp;過程:&nbsp;Export(ByRef p_oDbConn)
'&nbsp;描述:&nbsp;導(dǎo)出數(shù)據(jù)
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDbConn:&nbsp;數(shù)據(jù)庫連接對象
'
'*****************************************************
Public Sub Export(ByRef p_oDbConn)
&nbsp;Dim nI, nMaxI
&nbsp;Dim sTableName, sSQL
&nbsp;Dim sDataXML, sXSLStr
&nbsp;Dim sXMLStr
&nbsp;
&nbsp;If (Not IsArray(m_aSQlData)) Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_NotArray
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;ON ERROR RESUME NEXT
&nbsp;Set m_oXSLDOM&nbsp;= Server.CreateObject("Microsoft.XMLDOM")
&nbsp;Set m_oXMLDOM&nbsp;= Server.CreateObject("Microsoft.XMLDOM")
&nbsp;
&nbsp;If Err.Number <>0 Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_XMLDOM
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;
&nbsp;sXSLStr&nbsp;&nbsp;&nbsp;= GetXSL()&nbsp;&nbsp;
&nbsp;m_oXMLDOM.async&nbsp;= false&nbsp;
&nbsp;m_oXSLDOM.async&nbsp;= false
&nbsp;m_oXSLDOM.loadxml(sXSLStr)
&nbsp;
&nbsp;sDataXML&nbsp;= "<?xml version='1.0' encoding='" & m_sEncoding & "'?>"
&nbsp;sDataXML&nbsp;= sDataXML & "<DataBase>"
&nbsp;nMaxI&nbsp;= Ubound(m_aSQlData, 1)
&nbsp;For nI=0 To&nbsp;nMaxI
&nbsp;&nbsp;sTableName&nbsp;= m_aSQlData(nI, 0)
&nbsp;&nbsp;If (Len(sTableName) > 0) Then
&nbsp;&nbsp;&nbsp;sSQL&nbsp;&nbsp;= m_aSQlData(nI, 1)
&nbsp;&nbsp;&nbsp;sXMLStr&nbsp;&nbsp;= GetDataXML(sTableName, sSQL, p_oDbConn)
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;IF (m_nErrCode > m_nErrCode_NotErr) Then
&nbsp;&nbsp;&nbsp;&nbsp;Exit Sub
&nbsp;&nbsp;&nbsp;End IF
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;sDataXML&nbsp;= sDataXML & sXMLStr
&nbsp;&nbsp;End If&nbsp;&nbsp;
&nbsp;
&nbsp;Next
&nbsp;sDataXML&nbsp;= sDataXML & "</DataBase>"
&nbsp;
&nbsp;IF (m_bIsOutput) Then
&nbsp;&nbsp;Call ResponseXML(sDataXML)
&nbsp;End IF
&nbsp;
&nbsp;IF (m_bIsSave) Then
&nbsp;&nbsp;Call SaveDataXML(sDataXML)
&nbsp;End IF&nbsp;
&nbsp;
End Sub

'*****************************************************
'&nbsp;函數(shù):&nbsp;GetRndFileName()
'&nbsp;描述:&nbsp;獲得隨機(jī)名稱,由當(dāng)前時間和7位隨機(jī)數(shù)字構(gòu)成
'*****************************************************
Private Function GetRndFileName()
&nbsp;Dim nMax, nMin
&nbsp;Dim sRnd, sDate
&nbsp;Randomize
&nbsp;nMin&nbsp;= 1000000
&nbsp;nMax&nbsp;= 9999999
&nbsp;sRnd&nbsp;= Int( ( (nMax - nMin + 1) * Rnd ) + nMin)
&nbsp;sDate&nbsp;= Replace( Replace( Replace( now(), "-", "") , ":", ""), " ", "")
&nbsp;GetRndFileName&nbsp;= "_" & sDate & sRnd & ".xml"
&nbsp;
End Function

'*****************************************************
'&nbsp;函數(shù):&nbsp;GetXSL()
'&nbsp;描述:&nbsp;獲得XSL文件字符串
'*****************************************************
Private Function GetXSL()
&nbsp;Dim sXSLStr
&nbsp;sXSLStr&nbsp;= ""
&nbsp;sXSLStr&nbsp;= sXSLStr & "<?xml version='1.0' encoding='" & m_sEncoding & "'?>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<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'>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:output omit-xml-declaration='yes'/>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:template match='/'>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:for-each select='/xml/rs:data/z:row'>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:element name='Row'>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:for-each select='@*'>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:attribute name='{name()}'>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "<xsl:value-of select='.'/>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "</xsl:attribute>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "</xsl:for-each>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "</xsl:element>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "</xsl:for-each>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "</xsl:template>"
&nbsp;sXSLStr&nbsp;= sXSLStr & "</xsl:stylesheet>"
&nbsp;GetXSL&nbsp;= sXSLStr&nbsp;
&nbsp;
End Function

'*****************************************************
'&nbsp;函數(shù):&nbsp;GetDataXML(ByRef p_sTableName, ByRef p_sSQL, ByRef p_oDbConn)
'&nbsp;描述:&nbsp;執(zhí)行單條SQL,獲得數(shù)據(jù)轉(zhuǎn)換后的XML
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;1.p_sTableName&nbsp;:&nbsp;表的名稱
'&nbsp;&nbsp;&nbsp;2.p_sSQL&nbsp;&nbsp;:&nbsp;讀取數(shù)據(jù)的SQl語句
'&nbsp;&nbsp;&nbsp;3.p_oDbConn&nbsp;&nbsp;:&nbsp;數(shù)據(jù)庫連接對象
'
'*****************************************************
Private Function GetDataXML(ByRef p_sTableName, ByRef p_sSQL, ByRef p_oDbConn)
&nbsp;Dim oRecordset
&nbsp;Dim sXMLStr, sCleanXML
&nbsp;Dim nEnsData
&nbsp;ON ERROR RESUME NEXT
&nbsp;nEnsData&nbsp;&nbsp;= 0
&nbsp;Set oRecordset&nbsp;= p_oDbConn.Execute(p_sSQL)
&nbsp;If Err.Number <>0 Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_ReadData
&nbsp;&nbsp;Exit Function
&nbsp;End If
&nbsp;IF (Not oRecordset.eof) Then
&nbsp;&nbsp;nEnsData&nbsp;= 1
&nbsp;End IF
&nbsp;
&nbsp;IF (nEnsData = 1) Then
&nbsp;&nbsp;oRecordset.save m_oXMLDOM, 1
&nbsp;&nbsp;
&nbsp;&nbsp;oRecordset.close
&nbsp;&nbsp;Set oRecordset&nbsp;= Nothing
&nbsp;&nbsp;sCleanXML&nbsp;= m_oXMLDOM.transformNode(m_oXSLDOM)
&nbsp;&nbsp;sXMLStr&nbsp;&nbsp;= "<" & p_sTableName & ">"
&nbsp;&nbsp;sXMLStr&nbsp;&nbsp;= sXMLStr & sCleanXML
&nbsp;&nbsp;sXMLStr&nbsp;&nbsp;= sXMLStr & "</" & p_sTableName & ">"
&nbsp;Else
&nbsp;&nbsp;sXMLStr&nbsp;&nbsp;= "<" & p_sTableName & "/>"
&nbsp;End IF
&nbsp;

&nbsp;GetDataXML&nbsp;= sXMLStr
End Function

'*****************************************************
'&nbsp;過程:&nbsp;SaveDataXML(ByRef p_sXMLStr)
'&nbsp;描述:&nbsp;保存XML格式的字符串到文件
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;p_sXMLStr&nbsp;:&nbsp;XML格式的字符串
'*****************************************************
Private Sub SaveDataXML(ByRef p_sXMLStr)
&nbsp;Dim sFileInfo&nbsp;
&nbsp;If (Len(m_sSaveFileName) = 0) Then
&nbsp;&nbsp;m_sSaveFileName&nbsp;= GetRndFileName()
&nbsp;End If&nbsp;
&nbsp;
&nbsp;If (Len(m_sSaveFilePath) = 0) Then
&nbsp;&nbsp;sFileInfo&nbsp;= m_sSaveFileName
&nbsp;Else
&nbsp;&nbsp;IF (Right(m_sSaveFilePath,1) = "/")Then
&nbsp;&nbsp;&nbsp;sFileInfo&nbsp;= m_sSaveFilePath & m_sSaveFileName
&nbsp;&nbsp;Else&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;sFileInfo&nbsp;= m_sSaveFilePath & "/" & m_sSaveFileName
&nbsp;&nbsp;End IF&nbsp;&nbsp;
&nbsp;End If&nbsp;
&nbsp;m_oXMLDOM.loadxml(p_sXMLStr)
&nbsp;ON ERROR RESUME NEXT
&nbsp;m_oXMLDOM.save ( Server.MapPath(sFileInfo) )
&nbsp;If Err.Number <>0 Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_Save
&nbsp;&nbsp;Exit Sub
&nbsp;End If
End Sub
'*****************************************************
'&nbsp;過程:&nbsp;ResponseXML(ByRef p_sXMLStr)
'&nbsp;描述:&nbsp;輸出XML格式的字符串到瀏覽器
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;p_sXMLStr&nbsp;:&nbsp;XML格式的字符串
'*****************************************************
Private Sub ResponseXML(ByRef p_sXMLStr)
&nbsp;Response.CharSet&nbsp;&nbsp;= m_sEncoding
&nbsp;Response.ContentType&nbsp;= "text/xml"
&nbsp;Response.write p_sXMLStr
End Sub

'============================= 數(shù)據(jù)導(dǎo)出 End =============================
&nbsp;
'============================= 數(shù)據(jù)導(dǎo)入 Begin =============================
'*****************************************************
'&nbsp;過程:&nbsp;Import(ByRef p_oDbConn)
'&nbsp;描述:&nbsp;導(dǎo)入數(shù)據(jù)
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDbConn:&nbsp;數(shù)據(jù)庫連接對象
'
'*****************************************************
Public Sub Import(ByRef p_oDbConn)
&nbsp;Dim oRootNode
&nbsp;If (Len(m_sXMLFile) < 1) Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_EnsFile
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;ON ERROR RESUME NEXT
&nbsp;Set m_oXMLDOM&nbsp;= Server.CreateObject("Microsoft.XMLDOM")
&nbsp;
&nbsp;If Err.Number <>0 Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_XMLDOM
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;
&nbsp;m_oXMLDOM.async&nbsp;= false&nbsp;
&nbsp;m_oXMLDOM.load( Server.MapPath(m_sXMLFile) )
&nbsp;If Err.Number <>0 Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_EnsFile
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;If (Len(m_oXMLDOM.xml) < 1) Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_ErrFile
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;Set&nbsp;oRootNode&nbsp;= m_oXMLDOM.documentElement
&nbsp;Set m_oXMLDOM&nbsp;&nbsp;= Nothing
&nbsp;
&nbsp;m_sImportSQL&nbsp;= GetImportSQL(oRootNode)
&nbsp;Set oRootNode&nbsp;= Nothing
&nbsp;Call p_oDbConn.Execute(m_sImportSQL)
&nbsp;If Err.Number <>0 Then
&nbsp;&nbsp;m_nErrCode&nbsp;= m_nErrCode_WriteData
&nbsp;&nbsp;Exit Sub
&nbsp;End If
&nbsp;
End Sub

'*****************************************************
'&nbsp;函數(shù):&nbsp;GetImportSQL(ByRef p_oDataBase)
'&nbsp;描述:&nbsp;獲得將XML數(shù)據(jù)轉(zhuǎn)換為SQL后的字符串
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDataBase&nbsp;&nbsp;:&nbsp;XML文件的根節(jié)點
'
'*****************************************************
Private Function GetImportSQL(ByRef p_oDataBase)
&nbsp;Dim oTable, oRow, oDatas, oData
&nbsp;Dim sColNames, sColValues
&nbsp;Dim sColName
&nbsp;Dim sSQL, sTransactionSQL

&nbsp;sSQL&nbsp;= ""
&nbsp;For Each oTable In p_oDataBase.childNodes&nbsp;
&nbsp;
&nbsp;&nbsp;For Each oRow In oTable.childNodes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Set oDatas&nbsp;= oRow.selectNodes("@*")
&nbsp;&nbsp;&nbsp;&nbsp;sColNames&nbsp;= ""
&nbsp;&nbsp;&nbsp;&nbsp;sColValues&nbsp;= ""
&nbsp;&nbsp;&nbsp;&nbsp;For Each oData In oDatas
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sColName&nbsp;= oData.nodeName
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If ( Instr( Lcase(Cstr(m_sVacancyCols)), Lcase(Cstr("," & sColName & ",")) ) < 1) Then
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sColNames&nbsp;= sColNames & sColName & ", "&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sColValues&nbsp;= sColValues & "'" & oData.nodeValue & "', "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;Next
&nbsp;&nbsp;&nbsp;&nbsp;sColNames&nbsp;= "(" & Left(sColNames,Len(sColNames)-2) & ") "
&nbsp;&nbsp;&nbsp;&nbsp;sColValues&nbsp;= "(" & Left(sColValues,Len(sColValues)-2) & ") "
&nbsp;&nbsp;&nbsp;&nbsp;sSQL&nbsp;= sSQL & " Insert Into " & oTable.nodeName
&nbsp;&nbsp;&nbsp;&nbsp;sSQL&nbsp;= sSQL & " " & sColNames & " Values " & sColValues & " ;&nbsp; "
&nbsp;&nbsp;Next
&nbsp;Next
&nbsp;Set oData&nbsp;= Nothing
&nbsp;Set oDatas&nbsp;= Nothing
&nbsp;Set oRow&nbsp;= Nothing
&nbsp;Set oTable&nbsp;= Nothing
&nbsp;sTransactionSQL = "Set Xact_Abort On; "
&nbsp;sTransactionSQL = sTransactionSQL & " Begin Transaction; "
&nbsp;sTransactionSQL = sTransactionSQL & sSQL
&nbsp;sTransactionSQL = sTransactionSQL & " Commit Transaction; "
&nbsp;sTransactionSQL = sTransactionSQL & " Set Xact_Abort Off; "
&nbsp;GetImportSQL&nbsp;= sTransactionSQL
End Function
'============================= 數(shù)據(jù)導(dǎo)入 End =============================

'*****************************************************
'&nbsp;函數(shù):&nbsp;GetErrExegesis(ByRef p_nErrCode)
'&nbsp;描述:&nbsp;獲得錯誤代碼的注釋
'&nbsp;參數(shù):&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDataBase&nbsp;&nbsp;:&nbsp;XML文件的根節(jié)點
'
'*****************************************************
Public Function GetErrExegesis(ByRef p_nErrCode)
&nbsp;Dim sExegesis
&nbsp;Dim nErrCode
&nbsp;nErrCode&nbsp;= Cint(p_nErrCode)
&nbsp;
&nbsp;Select Case (nErrCode)
&nbsp;&nbsp;Case m_nErrCode_NotErr
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "運(yùn)行成功!"
&nbsp;&nbsp;Case m_nErrCode_NotArray
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "屬性: SQL語句數(shù)組 不正確!"
&nbsp;&nbsp;Case m_nErrCode_XMLDOM
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能創(chuàng)建XML文檔,服務(wù)器必須支持MSXML!"
&nbsp;&nbsp;Case m_nErrCode_ReadData
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "讀取數(shù)據(jù)庫數(shù)據(jù)發(fā)生錯誤! " & "<BR>"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & " 請檢查 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "1.數(shù)據(jù)庫是否已連接 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "2.語句是否正確 "
&nbsp;&nbsp;Case m_nErrCode_WriteData
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "寫入數(shù)據(jù)庫數(shù)據(jù)發(fā)生錯誤! " & "<BR>"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & " 請檢查 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "1.數(shù)據(jù)庫是否已連接 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "2.SQL語句是否正確 " & "<BR>"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "SQL語句 " & "<BR><BR>"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "" & m_sImportSQL
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;Case m_nErrCode_Save
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能保存XML文檔,請檢查是否對該目錄或文件有' 寫入權(quán)限 ' !"
&nbsp;&nbsp;Case m_nErrCode_EnsFile
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能讀取XM數(shù)據(jù),XML文件不存在 ' !"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "文件:" & m_sXMLFile
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;Case m_nErrCode_ErrFile
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能讀取XM數(shù)據(jù),XML文件格式錯誤 ' !"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "文件:" & m_sXMLFile
&nbsp;
&nbsp;&nbsp;Case Else
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "未知錯誤 !"
&nbsp;End Select
&nbsp;
&nbsp;GetErrExegesis&nbsp;= "<BR>" & sXSLStr & "<BR>"
&nbsp;
End Function
End Class
%>