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

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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
%>

不是很通吃,但某些情况下的运用足够了, 基本可以实现添加/删除/修改节点

脚本宝典总结

以上是脚本宝典为你收集整理的Asp操作Xml的精炼类,含示例代码全部内容,希望文章能够帮你解决Asp操作Xml的精炼类,含示例代码所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: