asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Tracking Web Page Visitors with XML
By Lai Yuen Kit
Rating: 3.8 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Overview

    The following code creates an XML file that lists information about the visitors to this page. The code can be found in visitorTrack.zip:

    After we've run the visitorTrack.asp, a new XML file, named "visitor.xml" will be created. Open the file with a browser. We will see the visitor's information (in this case, our information) as below:

    How It Works

    First, we start by creating an instance of an XML object. If you are using MSXML version 3, then remark, or comment out, the first statement and use the second line.

    Now we check for the existence of the file we need, visitor.xml. If the file is found, the objXML.load method will return a Boolean of True, otherwise it will return False. If the file does not exist, we need to create a new file by creating a Processing Instruction (<?xml version="1.0">) and appending a document element (<visitors>). This kind of checking also makes sure that we do not overwrite our records accidentally.

    The variable intID is used to emulate Primary Key / Identical Column which was found in RDBMS.

    Once we have checked for our XML file, we create another instance, named objXMLv. We create all the XML tags we want (<ID>, <HTTP_USER_AGENT>, etc.) and append it to objXMLv.

    After that, we can start supplying the values by using Request.ServerVariables properties.

    Now we can append the whole record to the Document Element (in this case, <visitors>). Setting the cloneNode to True will append the "<visitor>" element and its child elements as well.

    Finally we can save our XML file using the save() method.

    You can test your code at this point. After you have run your code, a new record will be added into visitor.xml. Try to open visitor.xml and see what you get!

    Presenting XML Records

    We'll create an ASP page that presents XML data in a more readable format. Your page should appear as shown:

    The following shows the code needed to generate the required page.

    How It Works

    We start by creating an instance of XMLDOM and load our visitor.xml into the instance.

    Once again, we check for the existence of the visitor.xml file. If the file cannot be found, we will display "No Record Found."

    Note that I use a "With" statement in the example. By using "With," we reduce the need for object to lookup and speed up the process a certain degree. This also helps us save a few keystrokes and makes the code less error-prone. (For more explanation, see http://msdn.microsoft.com/workshop/server/asp/ASPtips.asp)

    Variable intMaxRow and variable intMaxCol are used to store the maximum number of rows and the maximum number of columns, respectively. These variables will be used to iterate our records later on.

    Since any number in an XML object is zero-based, we need to subtract one from that value before we assign the number for "intMaxRow" and "intMaxCol."

    Now we can draw our table. To make our table more useful we will put the field names / tag names in the first row to make headers. Tag names are retrieved using the nodeName property.

    This part will be a little bit tricky. We'll use two For-Next blocks to iterate through the records. Basically the structure of our XML file is analogous to a two-dimensional array. We treat it using the same method used when dealing with two-dimensional arrays. If you have experience using the getrows() method in an ADO object, you can easily understand the concept here.

    Finally, we deference our XML object.

    Conclusion

    Now we are able to write some simple applications using XML. We can start building a more complex XML-driven Web application. Do bear in mind that, although implementation of XML is an effective yet economic option, storing sensitive information (such as credit card account numbers) in XML format is not recommended, since one can easily access the file without permission.

    About the Author

    Lai Yuen Kit, an ASP freelancer, is well versed in Flash, MS Access and SQL Server database technologies, Photoshop, XML, and, of course, HTML. He is proficient in the English, Chinese, and Malay languages. He can be reached at laiyuenkit@yahoo.com.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    Stonebroom.ASP2XML
    Stonebroom.ASP2XML(c) is an interface component designed to make building applications that transport data in XML format much easier. It can be used to automatically pass updates back to the original data source.
    [Top]
    Other Articles
    Sep 22, 2005 - Implementing Remote Calling Without Using AJAX
    Right now the latest buzzword around town is AJAX. AJAX is an acronym for Asynchronous JavaScript and XML and is a method used to implement remote calling. The problem is that AJAX is only implemented in ASP.NET 2.0. This article will show you one way to implement remote calling without using AJAX or the XMLHttpRequest object. The technique outlined can even be used from classic ASP and is sufficient for most remote calling needs.
    [Read This Article]  [Top]
    Aug 18, 2005 - SQL Server 2005 XQuery and XML-DML - Part 3
    This article is the third and final installment of Alex Homer's series covering the new XML support in Microsoft SQL Server 2005. In it he covers updating the contents of xml columns, comparing traditional XML update techniques with XQuery, and using XQuery in a managed code stored procedure.
    [Read This Article]  [Top]
    Aug 11, 2005 - SQL Server 2005 XQuery and XML-DML - Part 2
    In the second part of his series on SQL Server 2005's new XML support, Alex Homer looks at extracting data from XML columns, comparing traditional XML data access approaches with XQuery, and combining XQuery and XSL-T.
    [Read This Article]  [Top]
    Aug 3, 2005 - SQL Server 2005 XQuery and XML-DML - Part 1
    Microsoft SQL Server 2005 now offers great support for and close integration with XML as a data persistence format. In the first article of his series examining this new support, Alex Homer offers an overview of how SQL Server 2005 stores XML documents and schemas, examines how it supports querying and manipulating XML documents, and provides a simple test application that allows you to experiment with XQuery.
    [Read This Article]  [Top]
    Jun 30, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 3, Cont'd
    In the final article of his series on reading and writing XML in .NET 2.0, Alex Homer looks at how the updated XML document store objects XmlDocument, XmlDataDocument and PathDocument can be used to read, persist and write XML documents and fragments more easily and more efficiently than in .NET 1.x.
    [Read This Article]  [Top]
    Jun 29, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 3
    In the final article of his series on reading and writing XML in .NET 2.0, Alex Homer looks at how the updated XML document store objects XmlDocument, XmlDataDocument and PathDocument can be used to read, persist and write XML documents and fragments more easily and more efficiently than in .NET 1.x.
    [Read This Article]  [Top]
    Jun 16, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 2, Cont'd
    Alex Homer continues his series on reading and writing XML in .NET 2.0. In part one, we focused on the reading side of things, examining the XmlReader and XmlReaderSettings classes. In this article, we move on to look at the XmlWriter and XmlWriterSettings classes, and how they can be used to write XML documents and fragments more easily and more efficiently than in version 1.x of .NET.
    [Read This Article]  [Top]
    Jun 15, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 2
    Alex Homer continues his series on reading and writing XML in .NET 2.0. In part one, we focused on the reading side of things, examining the XmlReader and XmlReaderSettings classes. In this article, we move on to look at the XmlWriter and XmlWriterSettings classes, and how they can be used to write XML documents and fragments more easily and more efficiently than in version 1.x of .NET.
    [Read This Article]  [Top]
    Jun 2, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 1, Cont'd
    In the first part of his series on reading and writing XML in .NET 2.0, Alex Homer discusses the XmlReader and XmlReaderSettings classes. The XmlReader exposes several useful new features and the all new XmlReaderSettings class makes it easy to generate single or multiple instances of an XmlReader with a range of useful properties.
    [Read This Article]  [Top]
    Jun 1, 2005 - Reading and Writing XML in .NET Version 2.0 - Part 1
    In the first part of his series on reading and writing XML in .NET 2.0, Alex Homer discusses the XmlReader and XmlReaderSettings classes. The XmlReader exposes several useful new features and the all new XmlReaderSettings class makes it easy to generate single or multiple instances of an XmlReader with a range of useful properties.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers