复制代码 代码如下:
Class XMLClass
Private objXml
Private xmlDoc
Private xmlPath
'//============================================================
'
Sub Class_initialize
Set objXml = Server.CreateObject("MSXML2.DOMDocument")
objXml.preserveWhiteSpace = true
objXml.async = false
End Sub
Sub Class_Terminate
Set objXml = Nothing
End Sub
'//============================================================
'
Public Function CreateNew(sName)
Set tmpNode = objXml.createElement(sName)
objXml.appendChild(tmpNode)
Set CreateNew = tmpNode
End Function
'
Public Function OpenXml(sPath)
OpenXml=False
sPath=Server.MapPath(sPath)
'Response.Write(sPath)
xmlPath = sPath
If objXml.load(sPath) Then
Set xmlDoc = objXml.documentElement
OpenXml=True
End If
End Function
'
Public Sub LoadXml(sStr)
objXml.loadXML(sStr)
Set xmlDoc = objXml.documentElement
End Sub
Public Sub InceptXml(xObj)
Set objXml = xObj
Set xmlDoc = xObj.documentElement
End Sub
'//============================================================
'
Public Function AddNode(sNode,rNode)
' sNode STRING 节点名称
' rNode OBJECT 增加节点的上级节点引用
'=============================================================
Dim TmpNode
Set TmpNode = objXml.createElement(sNode)
rNode.appendChild TmpNode
Set AddNode = TmpNode
End Function
'
Public Function AddAttribute(sName,sValue,oNode)
' sName STRING 属性名称
' sValue STRING 属性值
' oNode OBJECT 增加属性的对象
'=============================================================
oNode.setAttribute sName,sValue
End Function
'
Public Function AddText(FStr,cdBool,oNode)
Dim tmpText
If cdBool Then
Set tmpText = objXml.createCDataSection(FStr)
Else
Set tmpText = objXml.createTextNode(FStr)
End If
oNode.appendChild tmpText
End Function
'========================================================================================================
'
Public Function GetAtt(aName,oNode)
' aName STRING 属性名称
' oNode OBJECT 节点引用
'=============================================================
dim tmpValue
tmpValue = oNode.getAttribute(aName)
GetAtt = tmpValue
End Function
'
Public Function GetNodeName(oNode)
' oNode OBJECT 节点引用
GetNodeName = oNode.nodeName
End Function
'
Public Function GetNodeText(oNode)
' oNode OBJECT 节点引用
GetNodeText = oNode.childNodes(0).nodeValue
End Function
'
Public Function GetNodeType(oNode)
' oNode OBJECT 节点引用
GetNodeType = oNode.nodeValue
End Function
'
Public Function FindNodes(sNode)
Dim tmpNodes
Set tmpNodes = objXml.getElementsByTagName(sNode)
Set FindNodes = tmpNodes
End Function
'
Public Function FindNode(sNode)
Private objXml
Private xmlDoc
Private xmlPath
'//============================================================
'
Sub Class_initialize
Set objXml = Server.CreateObject("MSXML2.DOMDocument")
objXml.preserveWhiteSpace = true
objXml.async = false
End Sub
Sub Class_Terminate
Set objXml = Nothing
End Sub
'//============================================================
'
Public Function CreateNew(sName)
Set tmpNode = objXml.createElement(sName)
objXml.appendChild(tmpNode)
Set CreateNew = tmpNode
End Function
'
Public Function OpenXml(sPath)
OpenXml=False
sPath=Server.MapPath(sPath)
'Response.Write(sPath)
xmlPath = sPath
If objXml.load(sPath) Then
Set xmlDoc = objXml.documentElement
OpenXml=True
End If
End Function
'
Public Sub LoadXml(sStr)
objXml.loadXML(sStr)
Set xmlDoc = objXml.documentElement
End Sub
Public Sub InceptXml(xObj)
Set objXml = xObj
Set xmlDoc = xObj.documentElement
End Sub
'//============================================================
'
Public Function AddNode(sNode,rNode)
' sNode STRING 节点名称
' rNode OBJECT 增加节点的上级节点引用
'=============================================================
Dim TmpNode
Set TmpNode = objXml.createElement(sNode)
rNode.appendChild TmpNode
Set AddNode = TmpNode
End Function
'
Public Function AddAttribute(sName,sValue,oNode)
' sName STRING 属性名称
' sValue STRING 属性值
' oNode OBJECT 增加属性的对象
'=============================================================
oNode.setAttribute sName,sValue
End Function
'
Public Function AddText(FStr,cdBool,oNode)
Dim tmpText
If cdBool Then
Set tmpText = objXml.createCDataSection(FStr)
Else
Set tmpText = objXml.createTextNode(FStr)
End If
oNode.appendChild tmpText
End Function
'========================================================================================================
'
Public Function GetAtt(aName,oNode)
' aName STRING 属性名称
' oNode OBJECT 节点引用
'=============================================================
dim tmpValue
tmpValue = oNode.getAttribute(aName)
GetAtt = tmpValue
End Function
'
Public Function GetNodeName(oNode)
' oNode OBJECT 节点引用
GetNodeName = oNode.nodeName
End Function
'
Public Function GetNodeText(oNode)
' oNode OBJECT 节点引用
GetNodeText = oNode.childNodes(0).nodeValue
End Function
'
Public Function GetNodeType(oNode)
' oNode OBJECT 节点引用
GetNodeType = oNode.nodeValue
End Function
'
Public Function FindNodes(sNode)
Dim tmpNodes
Set tmpNodes = objXml.getElementsByTagName(sNode)
Set FindNodes = tmpNodes
End Function
'
Public Function FindNode(sNode)
内容版权声明:除非注明,否则皆为本站原创文章。