明辉手游网中心:是一个免费提供流行视频软件教程、在线学习分享的学习平台!

ADO数据与XML数据间的转换的类(ASP完成)

[摘要]当对现有数据库的数据进行分析时,经常需要对某一部分的数据进行分析.此时,使用1.SQL查询分析器? 但其往往不直观,查找某个关键字又需要重新执行新的SQL.2.SQLXML模板? 但又不一定有权限建立新的虚拟目录,且某些SQL语句SQLXML模板不支持数据拆离时也有相似问题。尤其当不同网络,不同环...
当对现有数据库的数据进行分析时,经常需要对某一部分的数据进行分析.此时,使用
1.SQL查询分析器?
 但其往往不直观,查找某个关键字又需要重新执行新的SQL.
2.SQLXML模板?
 但又不一定有权限建立新的虚拟目录,且某些SQL语句SQLXML模板不支持
数据拆离时也有相似问题。
尤其当不同网络,不同环境,需要重新导入数据,进行分析或拆离,困难尤为明显。
能不能有一种方法,可以将数据脱离于数据库进行分析,需要时再导入到数据库中?
XML是个很好的选择!
ADO本身支持数据到XML的转换,只需要对其格式进行解析,成为自己的XML文件通用格式,就可以进行本地分析
而对通用XML格式进行数据库映射,就可完成数据重新导入数据库的工作.
下面是一个ADO数据(表的基本数据)与XML数据间的相互转换的类(ASP实现),初步完成表数据的导入、导出。
通用表间关系映射(通过XSD描述),考虑之中,希望各位赐教指点,不胜感激.
一个调用类的例子:
example.asp
<!--#include file="transformData.asp"-->
<%
Dim aSQL(1,1)
Dim oXMLData
'====== 连接数据库过程 ======
'获得数据库连接对象 oDbConn
'====== 连接数据库过程 ======
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;// 当对象属性有默认值(default())时,可以不用在赋值
Sub Export()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;&nbsp; // 导出数据
&nbsp;oXMLData.aSQlData&nbsp;&nbsp;= aSQL&nbsp;&nbsp;&nbsp;
&nbsp;' 必须&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2维SQL语句数组
&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数据
&nbsp;
&nbsp;oXMLData.sSaveFileName&nbsp;= "Data.xml"&nbsp;
&nbsp;' default(当前时间加随机数)&nbsp;如果保存XML数据,XML文件名称
&nbsp;
&nbsp;oXMLData.sSaveFilePath&nbsp;= ""&nbsp;&nbsp;&nbsp;
&nbsp;' default("")&nbsp;&nbsp;&nbsp;&nbsp;如果保存XML数据,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;' // 导出数据过程
&nbsp;IF (oXMLData.nErrCode<>0) Then&nbsp;&nbsp;' nErrCode(错误代码)为0,运行成功
&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; // 导入数据
&nbsp;oXMLData.sXMLFile&nbsp;&nbsp;= "Data.xml"&nbsp;' 必须&nbsp;&nbsp;数据源XML文件(包含相对路径)&nbsp;
&nbsp;oXMLData.sVacancyCols&nbsp;= "nLabelID"&nbsp;' 必须&nbsp;&nbsp;指定某些字段的值可以不导入(屏蔽字段)
&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 "数据导入成功!"
&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;创 建 人&nbsp;:&nbsp;moonpiazza
'&nbsp;日&nbsp;&nbsp;&nbsp; 期&nbsp;:&nbsp;2003.5.21
'&nbsp;描&nbsp;&nbsp;&nbsp; 述&nbsp;:&nbsp;ADO数据与XML数据间的转换(ASP实现)
'&nbsp;版&nbsp;&nbsp;&nbsp; 本&nbsp;:&nbsp;1.0
'&nbsp;功&nbsp;&nbsp;&nbsp; 能&nbsp;:&nbsp;&nbsp; ADO数据(表的基本数据)与XML数据间的相互转换
'&nbsp;待 改 进&nbsp;:&nbsp;表间数据的关联性(通用),数据量大时速度问题
'
'&nbsp;版&nbsp;权&nbsp;:&nbsp;欢迎改进,翻版不究&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;状态:&nbsp;可写
'&nbsp;类型:&nbsp;2维数组&nbsp;
'&nbsp;描述:&nbsp;SQL语句数组,1维是表名称,2维是相应SQL语句
'*****************************************************
Public Property Let aSQlData(ByRef p_aSQlData)
&nbsp;m_aSQlData&nbsp;= p_aSQlData
End Property

'*****************************************************
'&nbsp;属性:&nbsp;bIsSave
'&nbsp;状态:&nbsp;可写
'&nbsp;类型:&nbsp;数字(0,1)&nbsp;default(1)
'&nbsp;描述:&nbsp;导出数据时,是否保存为XML文件&nbsp;
'*****************************************************
Public Property Let bIsSave(ByRef p_bIsSave)
&nbsp;m_bIsSave&nbsp;= Cint(p_bIsSave)
End Property

'*****************************************************
'&nbsp;属性:&nbsp;bIsOutput
'&nbsp;状态:&nbsp;可写
'&nbsp;类型:&nbsp;数字(0,1)&nbsp;default(0)
'&nbsp;描述:&nbsp;导出数据时,是否显示XML数据
'*****************************************************
Public Property Let bIsOutput(ByRef p_bIsOutput)
&nbsp;m_bIsOutput&nbsp;= Cint(p_bIsOutput)
End Property

'*****************************************************
'&nbsp;属性:&nbsp;sSaveFileName
'&nbsp;状态:&nbsp;可写,可读
'&nbsp;类型:&nbsp;字符串&nbsp;default(GetRndFileName())
'&nbsp;描述:&nbsp;导出数据时,如果保存XML数据,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;状态:&nbsp;可写,可读
'&nbsp;类型:&nbsp;字符串&nbsp;default("")
'&nbsp;描述:&nbsp;导出数据时,如果保存XML数据,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;状态:&nbsp;可写
'&nbsp;类型:&nbsp;字符串&nbsp;
'&nbsp;描述:&nbsp;导入数据时,数据源XML文件(包含相对路径)&nbsp;
'*****************************************************
Public Property Let sXMLFile(ByRef p_sXMLFile)
&nbsp;m_sXMLFile&nbsp;= p_sXMLFile
End Property

'*****************************************************
'&nbsp;属性:&nbsp;sVacancyCols
'&nbsp;状态:&nbsp;可写
'&nbsp;类型:&nbsp;字符串&nbsp;default("")
'&nbsp;&nbsp;&nbsp;格式&nbsp; &nbsp;"nID,dDate"&nbsp; (以‘,’分隔字段)
'&nbsp;描述:&nbsp;导入数据时,指定某些字段的值可以不导入(屏蔽字段)
'*****************************************************
Public Property Let sVacancyCols(ByRef p_sVacancyCols)
&nbsp;m_sVacancyCols&nbsp;= "," & p_sVacancyCols & ","
End Property

'*****************************************************
'&nbsp;属性:&nbsp;nErrCode
'&nbsp;状态:&nbsp;可读
'&nbsp;类型:&nbsp;数字 &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;状态:&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;状态:&nbsp;可读
'&nbsp;类型:&nbsp;字符串&nbsp;default("gb2312")
'&nbsp;描述:&nbsp;导入数据时,生成的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

'============================= 数据导出 Begin =============================
'*****************************************************
'&nbsp;过程:&nbsp;Export(ByRef p_oDbConn)
'&nbsp;描述:&nbsp;导出数据
'&nbsp;参数:&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDbConn:&nbsp;数据库连接对象
'
'*****************************************************
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;函数:&nbsp;GetRndFileName()
'&nbsp;描述:&nbsp;获得随机名称,由当前时间和7位随机数字构成
'*****************************************************
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;函数:&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;函数:&nbsp;GetDataXML(ByRef p_sTableName, ByRef p_sSQL, ByRef p_oDbConn)
'&nbsp;描述:&nbsp;执行单条SQL,获得数据转换后的XML
'&nbsp;参数:&nbsp;
'&nbsp;&nbsp;&nbsp;1.p_sTableName&nbsp;:&nbsp;表的名称
'&nbsp;&nbsp;&nbsp;2.p_sSQL&nbsp;&nbsp;:&nbsp;读取数据的SQl语句
'&nbsp;&nbsp;&nbsp;3.p_oDbConn&nbsp;&nbsp;:&nbsp;数据库连接对象
'
'*****************************************************
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;参数:&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;参数:&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

'============================= 数据导出 End =============================
&nbsp;
'============================= 数据导入 Begin =============================
'*****************************************************
'&nbsp;过程:&nbsp;Import(ByRef p_oDbConn)
'&nbsp;描述:&nbsp;导入数据
'&nbsp;参数:&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDbConn:&nbsp;数据库连接对象
'
'*****************************************************
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;函数:&nbsp;GetImportSQL(ByRef p_oDataBase)
'&nbsp;描述:&nbsp;获得将XML数据转换为SQL后的字符串
'&nbsp;参数:&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDataBase&nbsp;&nbsp;:&nbsp;XML文件的根节点
'
'*****************************************************
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
'============================= 数据导入 End =============================

'*****************************************************
'&nbsp;函数:&nbsp;GetErrExegesis(ByRef p_nErrCode)
'&nbsp;描述:&nbsp;获得错误代码的注释
'&nbsp;参数:&nbsp;
'&nbsp;&nbsp;&nbsp;p_oDataBase&nbsp;&nbsp;:&nbsp;XML文件的根节点
'
'*****************************************************
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;= "运行成功!"
&nbsp;&nbsp;Case m_nErrCode_NotArray
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "属性: SQL语句数组 不正确!"
&nbsp;&nbsp;Case m_nErrCode_XMLDOM
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能创建XML文档,服务器必须支持MSXML!"
&nbsp;&nbsp;Case m_nErrCode_ReadData
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "读取数据库数据发生错误! " & "<BR>"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & " 请检查 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "1.数据库是否已连接 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "2.语句是否正确 "
&nbsp;&nbsp;Case m_nErrCode_WriteData
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "写入数据库数据发生错误! " & "<BR>"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & " 请检查 " & " "
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "1.数据库是否已连接 " & " "
&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文档,请检查是否对该目录或文件有' 写入权限 ' !"
&nbsp;&nbsp;Case m_nErrCode_EnsFile
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能读取XM数据,XML文件不存在 ' !"
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= sXSLStr & "文件:" & m_sXMLFile
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;Case m_nErrCode_ErrFile
&nbsp;&nbsp;&nbsp;sXSLStr&nbsp;= "不能读取XM数据,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
%>