Basic XML
page 1 of 1
Published: 21 Sep 2003
Unedited - Community Contributed
Abstract
XML is one of those buzzwords that appears all over the place, whether discussing data-interchange, content management, syndication, crm, erp, blah blah. In this article I am not going to explain what XML is, I assume you already know that. This article simply shows a method for writing values to an XML file from a form.
by Chris Garrett
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 18790/ 42

Basic XML

 

XML is one of those buzzwords that appears all over the place, wether discussing data-interchange, content management, syndication, crm, erp, blah blah.

In this article I am not going to explain what XML is, I assume you already know that, this article simply shows a method for writing values to an XML file from a form.

For the purposes of this tutorial please imagine we are going to keep our contacts email addresses in an XML file. We are happy for the moment to display the results using the plain XML file in IE.

View Source
http://authors.aspalliance.com/chrisg/tools/view-xml1.asp.asp

Download File
http://authors.aspalliance.com/chrisg/tools/download.asp?file=xml1.asp

The first 30 or so lines deal with displaying the html form if no data has been posted. This allows us to use the same script to enter the data and write the XML.

When a user enters the contact name and email address, WriteXML subroutine is called and the XML file is created if it does not already exist (lines 43-56). Creating an XML file consists of setting up an XML object and writing the top lines of the file and the top element (tag) (lines 52-53). oXML.load(strXMLFile) returns false if the file does not exist.

If the file does exist we count how many nodes are there for later use as an incremental ID.

Line 60 creates our new contact element/record, with the ID number as an attribute.

Next we need to add our childnodes/fields for name, email address and a datestamp. We do this with the following code.

oXMLRec.appendChild(oXML.createElement("name")) 
71 oXMLRec.childnodes(0).text = request.form("name") 

Basically means "append a child node with this name then set its value to this".

All what remains is to write away the record, then redirect to the XML which IE will hopefully read correctly and display in a nice tree view :O)



User Comments

Title: First timer   
Name: Dave
Date: 2010-02-23 4:46:15 AM
Comment:
Thanks for this guide, its great
Title: excellent   
Name: suresh
Date: 2008-04-01 9:14:49 AM
Comment:
good examples
Title: nice   
Name: abdulla hussein
Date: 2007-04-04 2:50:56 PM
Comment:
it is nice example that learn you xml basic with a simple languge, thank you its help :D
Title: XML file   
Name: kavitha
Date: 2006-01-31 1:07:08 AM
Comment:
GOOD JOB ITS WORKING

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2017 ASPAlliance.com  |  Page Processed at 2017-03-23 2:24:01 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search