Create an XML file
In this example we are going to create a simple XML document on the web server . The structure of the document will be as follows .
<?xml version=”1.0″ ?>
<news>
<newsitem>
<title>programmingsite.co.ukP</title>
<link>http://www.programmingsite.co.uk</link>
<description>programming resources</description>
</newsitem>
</news>
Anyway lets go with the code to create this example
<%@LANGUAGE = “VBScript” %>
<%
Response.Buffer = False
‘ensure proper headers sent to the client
Response.ContentType = “text/xml”
%>
<?xml version=”1.0″?>
<%
‘these are our variables
Dim objXML , objNews
‘create an instance of the DOM
Set objXML = Server.CreateObject(”Microsoft.XMLDOM”)
‘Create our root element using the createElement method
Set objXML.documentElement = objXML.createElement(”news”)
‘Create the newsitem element
Set objNews = objXML.createElement(”newsitem”)
‘now we will create all the child elements in this case
‘title , link and description
objNews.appendChild objXML.createElement(”title”)
objNews.appendChild objXML.createElement(”link”)
objNews.appendChild objXML.createElement(”description”)
‘now we add values to the child elements
objNews.childNodes(0).text = “programmingsite.co.uk”
objNews.childNodes(1).text = “http://www.programmingsite.co.uk”
objNews.childNodes(2).text = “programming resources”
‘add the newsitem element to the news element
objXML.documentElement.appendChild objNews.cloneNode(true)
‘write the document using the xml method of the DOM
Response.Write objXML.xml
%>
Related posts:
- Create a word document <?php $word = new COM(”word.application”) or die (”couldnt create an...
- Create an Adrotator Step 1 : Save the following as adrotator.txt , create...
- Saving a CSV file to a database Create a database in access called stock.mdb . Now create...
- create a text file Private Sub Form_Load() Dim objFSO As New FileSystemObject Dim objFile...
Related posts brought to you by Yet Another Related Posts Plugin.



















































on March 8th, 2009 at 1:30 pm
I have just copy and paste your script and host it at this URL but there is a HTTP 500 error.
http://www.londonfaces.co.uk/xml.asp.
Any idea?
on March 8th, 2009 at 6:33 pm
Ensure that the script has double quotes “, looking at the page it seems to have displayed a different character in wordpress
on April 26th, 2009 at 3:51 pm
Hi,
I was tried to use this code. Its working. But i got error page in my browser like,
XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/iridium/testsamplexml.asp
Line Number 2, Column 1:
^
May I know why this error coming. and how can I clear that?????
Thanks,
Saraf