Asp操作Xml的精煉類(lèi),含示例代碼
更新時(shí)間:2010年04月22日 19:24:20 作者:
自己寫(xiě)的一個(gè)Asp操作Xml的精煉類(lèi),有示例哦
以下保存成 App.xml , 與asp文件放在相同目錄下!
<?xml version="1.0" encoding="utf-8"?>
<Root>
<About>
<Version>1.0 Beta</Version>
<LatestVersion>1.0 Beta</LatestVersion>
<Author>Author</Author>
<PubDate>2010/02/20</PubDate>
</About>
<Config>
<Installed>False</Installed>
<BakPath>_Data</BakPath>
</Config>
</Root>
以下為Asp類(lèi)及使用方法,請(qǐng)保存成test.asp, 測(cè)試運(yùn)行
<%
Class AppConfig
Dim XmlDom
Private Sub Class_Initialize()
Set XmlDom = Server.createobject("microsoft.xmldom")
XmlDom.load(Server.mappath("App.xml"))
End Sub
Private Sub Class_Terminate()
Set XmlDom = Nothing
End Sub
Function GetD(key)
GetD =XmlDom.getElementsByTagName(key)(0).text
End Function
Function SetD(key,val)
XmlDom.getElementsByTagName(key)(0).text = val
XmlDom.save(Server.mappath("App.xml"))
End Function
Function AddD(node,key,val)
Set newnode=XmlDom.getElementsByTagName(node)(0).appendchild(XmlDom.createelement(key))
newnode.text = val
Set newnode=Nothing
XmlDom.save(Server.mappath("App.xml"))
End Function
Function DelD(key)
On Error Resume Next
XmlDom.getElementsByTagName(key)(0).parentNode.removechild(XmlDom.getElementsByTagName(key)(0))
XmlDom.save(Server.mappath("App.xml"))
End Function
End Class
Set Config = new AppConfig
wn Config.GetD("Version")
wn Config.GetD("LatestVersion")
wn Config.GetD("Author")
wn Config.GetD("PubDate")
wn Config.GetD("Installed")
wn Config.GetD("BakPath")
' 去掉相應(yīng)的注釋符,即可看到 [添加 / 編輯 / 刪除] 節(jié)點(diǎn)的效果
'Call Config.AddD("Config","test","test") ' 添加節(jié)點(diǎn)
'Call Config.SetD("test","test2") ' 編輯節(jié)點(diǎn)
'Call Config.DelD("test") ' 刪除節(jié)點(diǎn)
Sub wn(str)
Response.Write(str)&"<br />"&vbcrlf
End Sub
%>
不是很通吃,但某些情況下的運(yùn)用足夠了, 基本可以實(shí)現(xiàn)添加/刪除/修改節(jié)點(diǎn)
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<Root>
<About>
<Version>1.0 Beta</Version>
<LatestVersion>1.0 Beta</LatestVersion>
<Author>Author</Author>
<PubDate>2010/02/20</PubDate>
</About>
<Config>
<Installed>False</Installed>
<BakPath>_Data</BakPath>
</Config>
</Root>
以下為Asp類(lèi)及使用方法,請(qǐng)保存成test.asp, 測(cè)試運(yùn)行
復(fù)制代碼 代碼如下:
<%
Class AppConfig
Dim XmlDom
Private Sub Class_Initialize()
Set XmlDom = Server.createobject("microsoft.xmldom")
XmlDom.load(Server.mappath("App.xml"))
End Sub
Private Sub Class_Terminate()
Set XmlDom = Nothing
End Sub
Function GetD(key)
GetD =XmlDom.getElementsByTagName(key)(0).text
End Function
Function SetD(key,val)
XmlDom.getElementsByTagName(key)(0).text = val
XmlDom.save(Server.mappath("App.xml"))
End Function
Function AddD(node,key,val)
Set newnode=XmlDom.getElementsByTagName(node)(0).appendchild(XmlDom.createelement(key))
newnode.text = val
Set newnode=Nothing
XmlDom.save(Server.mappath("App.xml"))
End Function
Function DelD(key)
On Error Resume Next
XmlDom.getElementsByTagName(key)(0).parentNode.removechild(XmlDom.getElementsByTagName(key)(0))
XmlDom.save(Server.mappath("App.xml"))
End Function
End Class
Set Config = new AppConfig
wn Config.GetD("Version")
wn Config.GetD("LatestVersion")
wn Config.GetD("Author")
wn Config.GetD("PubDate")
wn Config.GetD("Installed")
wn Config.GetD("BakPath")
' 去掉相應(yīng)的注釋符,即可看到 [添加 / 編輯 / 刪除] 節(jié)點(diǎn)的效果
'Call Config.AddD("Config","test","test") ' 添加節(jié)點(diǎn)
'Call Config.SetD("test","test2") ' 編輯節(jié)點(diǎn)
'Call Config.DelD("test") ' 刪除節(jié)點(diǎn)
Sub wn(str)
Response.Write(str)&"<br />"&vbcrlf
End Sub
%>
不是很通吃,但某些情況下的運(yùn)用足夠了, 基本可以實(shí)現(xiàn)添加/刪除/修改節(jié)點(diǎn)
您可能感興趣的文章:
- asp下將數(shù)據(jù)庫(kù)中的信息存儲(chǔ)至XML文件中
- asp access數(shù)據(jù)庫(kù)并生成XML文件范例
- Javascript+XMLHttpRequest+asp.net無(wú)刷新讀取數(shù)據(jù)庫(kù)數(shù)據(jù)
- ASP XML操作類(lèi)代碼
- ASP讀取XML實(shí)例 優(yōu)酷專(zhuān)輯采集程序 雷鋒版
- ASP XMLDom在服務(wù)器端操作XML文件的主要方法和實(shí)現(xiàn)
- ASP.NET+XML打造網(wǎng)絡(luò)硬盤(pán)原理分析
- asp xmlhttp下載一句話(huà)
- asp.net TreeView與XML三步生成列表樹(shù)
- Asp 解析 XML并分頁(yè)顯示源碼
- ASP.NET中XML轉(zhuǎn)JSON的方法實(shí)例
- ASP.net處理XML數(shù)據(jù)實(shí)例淺析
- ASP.NET XmlDocument類(lèi)詳解
- asp.net中XML如何做增刪改查操作
- asp控制xml數(shù)據(jù)庫(kù)的經(jīng)典代碼
相關(guān)文章
asp下生成目錄樹(shù)結(jié)構(gòu)的類(lèi)
本篇文章主要介紹了asp下生成目錄樹(shù)結(jié)構(gòu)的類(lèi),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2007-11-11ASP實(shí)現(xiàn)緩存類(lèi)無(wú)錯(cuò)版
ASP實(shí)現(xiàn)緩存類(lèi)無(wú)錯(cuò)版...2007-08-08一個(gè)ACCESS數(shù)據(jù)庫(kù)訪問(wèn)的類(lèi)
一個(gè)ACCESS數(shù)據(jù)庫(kù)訪問(wèn)的類(lèi)...2006-07-07ASP中利用execute實(shí)現(xiàn)動(dòng)態(tài)包含文件的方法
本文介紹了ASP中動(dòng)態(tài)包含ASP文件,并使其中ASP類(lèi)(Class)可實(shí)例化的方法,需要的朋友可以參考下2007-03-03