日期:2008-07-12  浏览次数:20546 次

<%
Class XMLDOMDocument
Private fNode,fANode
Private fErrInfo,fFileName,fOpen

Dim XMLDom

'返回节点的缩进字串
Private Property Get TabStr(byVal Node)
TabStr=""
If Node Is Nothing Then Exit Property
If not Node.parentNode Is nothing Then TabStr=" "&TabStr(Node.parentNode)
End Property

'返回一个子节点对象,ElementOBJ为父节点,ChildNodeObj要查找的节点,IsAttributeNode指出是否为属性对象
Public Property Get ChildNode(byVal ElementOBJ,byVal ChildNodeObj,byVal IsAttributeNode)
Dim Element
Set ChildNode=Nothing

If IsNull(ChildNodeObj) Then
If IsAttributeNode=false Then
Set ChildNode=fNode
Else
Set ChildNode=fANode
End If
Exit Property
ElseIf IsObject(ChildNodeObj) Then
Set ChildNode=ChildNodeObj
Exit Property
End If

Set Element=Nothing
If LCase(TypeName(ChildNodeObj))="string" and Trim(ChildNodeObj)<>"" Then
If IsNull(ElementOBJ) Then
Set Element=fNode
ElseIf LCase(TypeName(ElementOBJ))="string" Then
If Trim(ElementOBJ)<>"" Then
Set Element=XMLDom.selectSingleNode("//"&Trim(ElementOBJ))
If Lcase(Element.nodeTypeString)="attribute" Then Set Element=Element.selectSingleNode("..")
End If
ElseIf IsObject(ElementOBJ) Then
Set Element=ElementOBJ
End If

If Element Is Nothing Then
Set ChildNode=XMLDom.selectSingleNode("//"&Trim(ChildNodeObj))
ElseIf IsAttributeNode=true Then
Set ChildNode=Element.selectSingleNode("./@"&Trim(ChildNodeObj))
Else
Set ChildNode=Element.selectSingleNode("./"&Trim(ChildNodeObj))
End If
End If
End Property

'读取最后的错误信息
Public Property Get ErrInfo
ErrInfo=fErrInfo
End Property

'给XML内容
Public Property Get XMLText(byVal ElementOBJ)
XMLText=""
If fopen=false Then Exit Property

Set ElementOBJ=ChildNode(XMLDom,ElementOBJ,false)
If ElementOBJ Is Nothing Then Set ElementOBJ=XMLDom

XMLText=ElementOBJ.XML
End Property

'=================================================================
'类初始化
Private Sub Class_Initialize()
Set XMLDom=CreateObject("Microsoft.XMLDOM")
XMLDom.preserveWhiteSpace=true

Set fNode=Nothing
Set fANode=Nothing

fErrInfo=""
fFileName=""
fopen=false
End Sub

'类释放
Private Sub Class_Terminate()
Set fNode=Nothing
Set fANode=Nothing
Set XMLDom=nothing
fopen=false
End Sub

'=====================================================================
'建立一个XML文件,RootElementName:根结点名。XSLURL:使用XSL样式地址
'返回根结点
Function Create(byVal RootElementName,byVal XslUrl)
Dim PINode,RootElement

Set Create=Nothing

If (XMLDom Is Nothing) Or (fopen=true) Then Exit Function

If Trim(RootElementName)="" Then RootElementName="Root"

Set PINode=XMLDom.CreateProcessingInstruction("XML", "version=""1.0"" encoding=""GB2312""")
XMLDom.appendChild PINode

Set PINode=XMLDOM.CreateProcessingInstruction("XML-stylesheet"