加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

Asp操作Xml的精炼类,含示例代码分享

发布时间:2023-06-09 13:48:39 所属栏目:Asp教程 来源:
导读:自己写的一个Asp操作Xml的精炼类,有示例哦

以下保存成 App.xml , 与asp文件放在相同目录下!

复制代码代码如下:

<?xml version="1.0" encoding="utf-8"?>

<Root>

<About>

<Version>1.0 Beta<
自己写的一个Asp操作Xml的精炼类,有示例哦
 
以下保存成 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类及使用方法,请保存成test.asp, 测试运行
 
复制代码代码如下:
 
<%
 
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")
 
' 去掉相应的注释符,即可看到 [添加 / 编辑 / 删除] 节点的效果
 
'Call Config.AddD("Config","test","test") ' 添加节点
 
'Call Config.SetD("test","test2") ' 编辑节点
 
'Call Config.DelD("test") ' 删除节点
 
Sub wn(str)
 
Response.Write(str)&"<br />"&vbcrlf
 
End Sub
 
%>
 
不是很通吃,但某些情况下的运用足够了, 基本可以实现添加/删除/修改节点
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章