Xml generation using asp

Source: Internet
Author: User
Tags chr
The code is as follows: Copy code

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> add a new node to xml </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
<Style>
Body {font-size: 12px ;}
</Style>
</HEAD>

<BODY>
<! -- # Include file = "top. asp" -->
<%
Addok = request ("addok ")
If addok = "" Or IsNull (addok) Then
%>
<Form name = "form1" method = "post" action = "? Addok = add ">
Website name: <input type = "text" name = "site" size = "30">

Address: <input type = "text" name = "url" size = "40">

<Input type = "submit" value = "submit"> <input type = "reset" value = "reset">
</Form>
<%
End If
If addok = "add" then
Site = request ("site ")
Url = request ("url ")
StrSourceFile = Server. MapPath ("./") & "\ test. xml"
'Obtain the path of the XML file. The path varies depending on your virtual directory.
Set objXML = Server. CreateObject ("Microsoft. XMLDOM ")
'Create an XML object
ObjXML. load (strSourceFile)
'Read XML files into memory
Set objRootlist = objXML.doc umentElement. selectSingleNode ("root ")
'Select the <root> node
If objRootlist. hasChildNodes then
'Determine whether <NewList> has subnodes (because if there is no subnode for each <root> operation, an error will be returned if no subnode is added for the first operation.
Id = objRootlist. lastchild. firstchild. text + 1
'Obtain the ID number of the child node to be inserted. The ID number is the first child node (firstchild) of the last child node (lastchild) of <root>)
'Id' plus 1 (here we increase progressively according to The IDSN of the relational database)
Else
'If there is no word subnode, it is the first time the message ID is set to 1
Id = 1
End If
Brstr = chr (13) & chr (10) & chr (9)
XMLnode = brstr & "<list>" & vbnewline &_
"<Id>" & id & "</id>" & vbnewline &_
"<Name>" & site & "</name>" & vbnewline &_
"<Url>" & url & "</url>" & vbnewline &_
"<Time>" & Replace (Now (), "morning", ""), "afternoon", "") & "</time>" & vbnewline &_
"</List>" & vbnewline

'Create an XML segment based on the obtained data
Set objXML2 = Server. CreateObject ("Microsoft. XMLDOM ")
'Create a new XML object
ObjXML2.loadXML (XMLnode)
'Read XML snippets into memory
Set rootnewnode1_objxml2.doc umentElement
'Get the root node of objXML2
ObjRootlist. appendChild (rootNewNode)
'Insert XML fragments into test. xml
ObjXML. save (strSourceFile)
'Store the test. xml file (because test. xml is not stored and only updated in memory)
Set objXML = nothing
Set objXML2 = nothing
Response. Redirect ("index. asp ")
Response. end
End If
%>
</BODY>
</HTML>

The content in test. xml is
<? Xml version = "1.0" encoding = "gb2312"?>
<Site>
<Root>
<List>
<Id> 0 </id>
<Name> Sina </name>
<Url> http://www.sina.com.cn </url>
<Time> 10:10:10 </time>
</List>
</Root>
</Site>

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.