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

所属分类: 网络编程 / ASP编程 阅读数: 2022
收藏 0 赞 0 分享
以下保存成 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
%>

不是很通吃,但某些情况下的运用足够了, 基本可以实现添加/删除/修改节点
更多精彩内容其他人还在看

ASP 指南

ASP 指南
收藏 0 赞 0 分享

改进 ASP 的字符串处理性能

改进 ASP 的字符串处理性能
收藏 0 赞 0 分享

pjblog2的参数第1/2页

pjblog2的参数
收藏 0 赞 0 分享

ASP智能搜索的实现

ASP智能搜索的实现
收藏 0 赞 0 分享

网站生成静态页面攻略2:数据采集

网站生成静态页面攻略2:数据采集
收藏 0 赞 0 分享

网站生成静态页面攻略3:防采集策略

网站生成静态页面攻略3:防采集策略
收藏 0 赞 0 分享

网站生成静态页面攻略4:防采集而不防搜索引擎策略

网站生成静态页面攻略4:防采集而不防搜索引擎策略
收藏 0 赞 0 分享

简单分页函数一 常用

简单分页函数一 常用
收藏 0 赞 0 分享

asp最常用的分页函数

asp最常用的分页函数
收藏 0 赞 0 分享

LINE9的目录浏览源程序

LINE9的目录浏览源程序
收藏 0 赞 0 分享
查看更多