The XML refining class for ASP operations, including sample code

Source: Internet
Author: User

Save the following as app. XML, which is in the same directory as the ASP file! CopyCode The Code is 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 are ASP classes and usage methods. Save them as test. asp and run the test. Copy code The Code is as follows: <%
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 ")
'Remove the corresponding annotator to see the [Add/edit/delete] node Effect
'Call config. addd ("Config", "test", "test") 'to add a node
'Call config. setd ("test", "Test2") 'edit a node
'Call config. deld ("test") 'deletes a node.
Sub Wn (STR)
Response. Write (STR) & "<br/>" & vbcrlf
End sub
%>

Not a good choice, but in some cases it is enough to add, delete, or modify nodes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.