ASP operations xml--Display all nodes in the XML file

Source: Internet
Author: User
Tags add time

You typically use a database to save data, but you can also use an XML file to save data. Suppose the contents of the XML file are:
Test.xml
<?xml version= "1.0" encoding= "gb2312"?>
<site>
<root>
<list>
<id>0</id>
<name> Sina </name>
<url>http://www.sina.com.cn</url>
<time>2007-11-1 10:10:10</time>
</list>
<list>
<id>1</id>
<name>google</name>
<url>http://www.google.cn</url>
<time>2007-11-2 11:11:11</time>
</list>
</root>
</site>

ASP file to display the content in the XML
Index.asp
<style>
body {font-size:12px;}
</style>
<%
strSourceFile = Server.MapPath ("./") & "\test.xml"
' Get the path to the XML file, which is different depending on your virtual directory.
Set objxml = Server.CreateObject ("Microsoft.FreeThreadedXMLDOM")
' Create an XML pair as a free thread
Objxml.load (strsourcefile) ' reads the XML file into memory
Set objrootsite = ObjXML.documentElement.selectSingleNode ("root")
' Select the root node
Num=objrootsite.childnodes.length-1
For i=0 to Num
Response.Write "Site Name:" &objrootsite.childnodes.item (i) Childnodes.item (1) .text& "<a href=" "javascript: Delxml ("&objrootsite.childnodes.item (i). Childnodes.item (0) .text&") "" > Delete </a> <a href= "" Editxml.asp?id= "&objrootsite.childnodes.item (i) childnodes.item (0) .text&" "> Modify </a>
"
Response.Write "URL:" &objrootsite.childnodes.item (i) Childnodes.item (2) .text& "
"
Response.Write "Add Time:" &objrootsite.childnodes.item (i) Childnodes.item (3) .text& "

"
Next
%>
<script>
function Delxml (ID)
{
if (!confirm) are you sure you want to delete it? ")) return false;
location.href= ' delxml.asp?id= ' +id;
}
</script>

Note: index.asp to be placed in the same directory as the Test.xml file.

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.