I wrote a refined class for Asp to operate Xml. There are examples below. Save it as App.xml and put it in the same directory as the asp file!
Copy the code code as follows:
<?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>
The following is the Asp class and how to use it. Please save it as test.asp and test it.
Copy the code code as follows:
<%
ClassAppConfig
DimXmlDom
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)
' Remove the corresponding annotation to see the effect of the [Add/Edit/Delete] node
'Call Config.AddD(Config,test,test) 'Add node
'Call Config.SetD(test,test2) ' Edit node
'Call Config.DelD(test) ' Delete node
Sub wn(str)
Response.Write(str)&<br />&vbcrlf
End Sub
%>
It’s not very universal, but it’s enough for use in some situations. It can basically add/delete/modify nodes.