佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 一個(gè)asp版XMLDOM操作類

一個(gè)asp版XMLDOM操作類

熱門標(biāo)簽:科大訊飛語(yǔ)音識(shí)別系統(tǒng) Linux服務(wù)器 服務(wù)器配置 阿里云 Mysql連接數(shù)設(shè)置 電子圍欄 團(tuán)購(gòu)網(wǎng)站 銀行業(yè)務(wù)
script language="vbscript" runat="server">
'============================================================
'作者:做回自己
'時(shí)間:2005-3-15
============================================================
Class XMLClass
Private objXml
Private xmlDoc
Private xmlPath
'//============================================================
'!--類初始化及注銷時(shí)的事件-->
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
'//============================================================
'!--建立一個(gè)新的XML文檔-->
Public Function CreateNew(sName)
Set tmpNode = objXml.createElement(sName)
objXml.appendChild(tmpNode)
Set CreateNew = tmpNode
End Function
'!--從外部讀入XML文檔-->
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
'!--從外部讀入XML字符串-->
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
'//============================================================
'!--新增一個(gè)節(jié)點(diǎn)-->
Public Function AddNode(sNode,rNode)
' sNode STRING 節(jié)點(diǎn)名稱
' rNode OBJECT 增加節(jié)點(diǎn)的上級(jí)節(jié)點(diǎn)引用
'=============================================================
Dim TmpNode
Set TmpNode = objXml.createElement(sNode)
rNode.appendChild TmpNode
Set AddNode = TmpNode
End Function
'!--新增一個(gè)屬性-->
Public Function AddAttribute(sName,sValue,oNode)
' sName STRING 屬性名稱
' sValue STRING 屬性值
' oNode OBJECT 增加屬性的對(duì)象
'=============================================================
oNode.setAttribute sName,sValue
End Function
'!--新增節(jié)點(diǎn)內(nèi)容-->
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
'========================================================================================================
'!--取得節(jié)點(diǎn)指定屬性的值-->
Public Function GetAtt(aName,oNode)
' aName STRING 屬性名稱
' oNode OBJECT 節(jié)點(diǎn)引用
'=============================================================
dim tmpValue
tmpValue = oNode.getAttribute(aName)
GetAtt = tmpValue
End Function
'!--取得節(jié)點(diǎn)名稱-->
Public Function GetNodeName(oNode)
' oNode OBJECT 節(jié)點(diǎn)引用
GetNodeName = oNode.nodeName
End Function
'!--取得節(jié)點(diǎn)內(nèi)容-->
Public Function GetNodeText(oNode)
' oNode OBJECT 節(jié)點(diǎn)引用
GetNodeText = oNode.childNodes(0).nodeValue
End Function
'!--取得節(jié)點(diǎn)類型-->
Public Function GetNodeType(oNode)
' oNode OBJECT 節(jié)點(diǎn)引用
GetNodeType = oNode.nodeValue
End Function
'!--查找節(jié)點(diǎn)名相同的所有節(jié)點(diǎn)-->
Public Function FindNodes(sNode)
Dim tmpNodes
Set tmpNodes = objXml.getElementsByTagName(sNode)
Set FindNodes = tmpNodes
End Function
'!--查打一個(gè)相同節(jié)點(diǎn)-->
Public Function FindNode(sNode)
Dim TmpNode
Set TmpNode=objXml.selectSingleNode(sNode)
Set FindNode = TmpNode
End Function
'!--刪除一個(gè)節(jié)點(diǎn)-->
Public Function DelNode(sNode)
Dim TmpNodes,Nodesss
Set TmpNodes=objXml.selectSingleNode(sNode)
Set Nodesss=TmpNodes.parentNode
Nodesss.removeChild(TmpNodes)
End Function
'!--替換一個(gè)節(jié)點(diǎn)-->
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
'//--創(chuàng)建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
'//==================================================================================
'相關(guān)統(tǒng)計(jì)
'!--取得根節(jié)點(diǎn)-->
Property Get Root
Set Root = xmlDoc
End Property
'!--取得根節(jié)點(diǎn)下子節(jié)點(diǎn)數(shù)-->
Property Get Length
Length = xmlDoc.childNodes.length
End Property
'//==================================================================================
'相關(guān)測(cè)試
Property Get TestNode
TestNode = xmlDoc.childNodes(0).text
End Property
End Class
/script>

標(biāo)簽:廣元 江蘇 萍鄉(xiāng) 蚌埠 衢州 大理 棗莊 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《一個(gè)asp版XMLDOM操作類》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    宁都县| 南宫市| 游戏| 蓬莱市| 义马市| 千阳县| 化州市| 霍邱县| 志丹县| 宁德市| 新田县| 大兴区| 泸定县| 大庆市| 遂溪县| 镇原县| 巴林左旗| 汉源县| 汶川县| 克什克腾旗| 镇安县| 嘉荫县| 沧州市| 翼城县| 青海省| 宁武县| 临夏县| 嘉禾县| 麻栗坡县| 托克逊县| 鱼台县| 平阳县| 西青区| 三穗县| 石楼县| 衡东县| 黄大仙区| 桐柏县| 武宁县| 长寿区| 峨山|