LogoASPAlliance: Articles, reviews, and samples for .NET Developers
Basic XML
by Chris Garrett
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 11316/ 20

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

Download File

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.

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)

Product Spotlight
Product Spotlight 

©Copyright 1998-2022  |  Page Processed at 2022-10-01 10:57:42 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search