一个asp版XMLDOM操作类(2)
'<!--取得节点内容-->
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
'//=============================================================================
'<!--保存XML文档-->
Public Function SaveXML()
'ProcessingInstruction()
objXml.save(xmlPath)
End Function
'<!--另存XML文档-->
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
</script>
内容版权声明:除非注明,否则皆为本站原创文章。