ASP版XML操作类

29 篇文章 0 订阅
29 篇文章 0 订阅

www.u8686.com-信息发布平台

ASP版XML操作类

[code]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)
Dim TmpNode
Set TmpNode=objXml.selectSingleNode(sNode)
Set FindNode = TmpNode
End Function
'
Public Function DelNode(sNode)
Dim TmpNodes,Nodesss
Set TmpNodes=objXml.selectSingleNode(sNode)
Set Nodesss=TmpNodes.parentNode
Nodesss.removeChild(TmpNodes)
End Function
'
Public Function ReplaceNode(sNode,sText,cdBool)
'replaceChild
Dim TmpNodes,tmpText
Set TmpNodes=objXml.selectSingleNode(sNode)
'AddText sText,cdBool,TmpNodes
If cdBool Then
Set tmpText = objXml.createCDataSection(sText)
Else
Set tmpText = objXml.createTextNode(sText)
End If
TmpNodes.replaceChild tmpText,TmpNodes.firstChild
End Function

Private Function ProcessingInstruction
'//--创建XML声明
Dim objPi
Set objPi = objXML.createProcessingInstruction("xml", "version="&chr(34)&"1.0"&chr(34)&" encoding="&chr(34)&"gb2312"&chr(34))
'//--把xml生命追加到xml文档
objXML.insertBefore objPi, objXML.childNodes(0)
End Function
'//=============================================================================
'
Public Function SaveXML()
'ProcessingInstruction()
objXml.save(xmlPath)
End Function
'
Public Function SaveAsXML(sPath)
ProcessingInstruction()
objXml.save(sPath)
End Function
'//==================================================================================
'相关统计
'
Property Get Root
Set Root = xmlDoc
End Property
'
Property Get Length
Length = xmlDoc.childNodes.length
End Property
'//==================================================================================
'相关测试
Property Get TestNode
TestNode = xmlDoc.childNodes(0).text
End Property
End Class[/code]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值