Content feed Comments Feed

The Official ASATO Site

Hi, welcome to my blog. ASP,asp.net,Health,Javascript,JQUERY

Archive for the ‘ASP’ Category

Create a xml file with asp!

Posted by admin On April - 14 - 2010

The following example shows how to create a XML file with asp.
First, we write a function named “CreateXml”

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
	sub CreateXml(FilePath)
		startime=timer()
		dim XmlDoc,Root
		Set XmlDoc = Server.CreateObject("Microsoft.XMLDOM")
			XmlDoc.async = False
			Set Root = XmlDoc.createProcessingInstruction("xml","version='1.0' encoding='UTF-8'")
			XmlDoc.appendChild(Root)
			XmlDoc.appendChild(XmlDoc.CreateElement("files"))
			XmlDoc.Save(Server.MapPath(FilePath))
			Set Root = Nothing
		Set XmlDoc = Nothing
		LoadData(ZipPathDir)
		endtime=timer()
		response.Write("<span style=' color:#ff0000;'>time:" & FormatNumber((endtime-startime),3) & "s</span>")
 
	End sub

then,we can use it to create xml file.

?View Code CSHARP
1
2
3
Dim ZipPathFile
ZipPathFile = "update.xml"
CreateXml(ZipPathFile)

how to read XML file with asp?

Posted by admin On July - 1 - 2009

in this article,we will study how to reading xml file with asp.

first: what is xml file ?

XML is tag based just like HTML. there is a example:
<?xml version=”1.0″?>
<boot>
<name>Faisal Khan</name>
<name></name>
<name/>
<name language=”US-EN”>Faisal Khan</name>
</boot>

second: we save the xml file named “aspreadxml.xml”, and we will reading this xml with asp. we can get the xml document elements and attributes.
the code like this:

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0"?>
<%
dim xml,objNode,objAtr,nCntChd,nCntAtr
Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.Load(Server.MapPath("aspreadxml.xml"))
Set objNode=xml.documentElement
nCntChd=objNode.ChildNodes.length-1
for i=0 to nCntChd
set objAtr=objNode.ChildNodes.item(i)
nCntAtr=objAtr.Attributes.length-1
for j=0 to nCntAtr
response.write objAtr.Attributes.item(j).Text&"<br>"
next
response.write "<br>"
next
Set objAtr=Nothing
Set objNode=Nothing
Set xml=Nothing
%>