ZDNet UK


Skip to Main Content

ZDNet.co.uk - Winner of Best Business Website 2007
  1. Home
  2. News
  3. Blogs
  4. Reviews
  5. Prices
  6. Resources
  7. Community
  8. My ZDNet

 

ZDNet UK RSS Feeds


IT Jobs

Office applications Toolkit

Implement a flexible shopping basket with XML and ASP

Edmond Woychowsky Builder.com

Published: 03 Jul 2003 15:39 BST

  • Email
  • Trackback
  • Clip Link
  • Print friendly
  • Post Comment

There is no single way to create a virtual shopping basket. Recently I had the opportunity to rewrite a classic ASP shopping basket so that it had a similar look and feel, but was more flexible and faster than the original. I decided to take advantage of XML and develop a cross-browser solution. Let me tell you some of the issues I ran into and how I improved on the original design.

The old shopping basket
Since the original shopping basket was geared to a select group of customers, it relied more on user training instead of ease of use. Beyond emptying the shopping basket completely, no mechanism existed to make any changes to the contents. If you put the wrong item or quantity in the basket, you had to start over to correct the mistake.

Behind the scenes, the original shopping basket didn't get any better. A limited number of lines were displayed and the client would page through the shopping basket. The problem with this approach is everything was stored in a table based upon the ASP session ID. A query was performed when the client navigated the basket contents. In addition, if the session timed out, the shopping basket contents would exist in the table until somebody manually deleted it.

The new approach
I didn't want to repeat the mistakes of the past, so the new shopping basket would be XML-session base instead of table based. This approach has several advantages. First, the entire shopping basket is stored on the client-side in the form of an XML Data Island as shown in Listing A. This eliminates the need to query a table for simple navigation. Instead, MozillaDSO() and xmlPage() functions are used.

Along with navigation, the xmlPage() method provides functionality that the original shopping basket did not include-the ability to change quantities and delete items. Because it uses two XML Data islands-one bound, the other one not-changes to the bound Data island won't affect the unbound Data island until an update key is clicked. Once the update button is clicked, a mechanism, such as XMLHTTP, is used to transmit the changes to the server. If for some reason, you don't fully trust XMLHTTP in either Microsoft Internet Explorer or Mozilla, a hidden frame (i.e., iframe) along with a form and input box can be used to accomplish the same thing. Listing B shows the JavaScript behind the update function.

Before I go any further, I did use the words Mozilla and XMLHTTP in the same sentence. There is written proof that Mozilla (http://www.mozilla.org/xmlextras/supports XMLHTTP). While the syntax is a little different than that available in Internet Explorer, it is nothing that a little JavaScript can't handle. The complete client-side solution appears in Figure A and the ASP is shown in Listing C.

On the server-side
Once the client-side coding is complete, it is time to concentrate on the server-side of the shopping basket. The mechanism for building the shopping basket varies with the type of e-commerce system, but the basic layout for the XML Data island is shown in Listing D. Because this is a demo application, the code-behind portion of the client-side page (shown in Listing C) doesn't show how the shopping basket is initially created or contain any database logic. It concentrates on manipulating the shopping basket (shown in Listing D). Creating the shopping basket is accomplished with the XML Document Object Model (DOM) or through the use of the ADO save method and XSLT when the first item is selected. Subsequent items are simply appended using either the DOM or XSLT.

The checkout process is where the database logic resides. I navigate the XML shopping basket using the DOM and update or add rows using an Oracle stored procedure, which really wouldn't be very helpful to those using SQL Server or MySQL.

Better the second time
The use of XML Data islands has a tendency to give HTML a very clean look. Rather than having row after row of HTML sprinkled with server-side code or a single row of HTML embedded in a loop, there is one row of HTML. This method can help you avoid some of the maintenance nightmares that developers face when someone suggests adding a column as soon as your shopping basket application is complete.

  • Email
  • Trackback
  • Clip Link
  • Print friendly Print with Dell

Did you find this article useful?
41 out of 75 people found this useful



Company/Topic Alerts

Create a new alert from the list below:






Related Jobs

Front End Developer XHTML, CSS, Javascript, W3C

The successful candidate will need to: -Use information/interaction design skills to develop and document site structures, navigation flows, wire ...

Software Engineer - C#, .NET, Web Services - Reading - Insurance - 40k

Webforms using ASP.Net and C# XML, XSLT, XPath, XML Schemas, SOAP, AJAX, HTML, Javascript, CSS SQL Server (2000/2005) development using SQL and ...

Web Developer - XHTML, CSS, SEO- Surrey

The ideal candidate will have a proven commercial experience in table-less web development using CSS. Table-less XHTML and CSS Coding to W3C ...

Featured Talkback

Why do so many (virtually all) software packages think that they are so important that they have to be started automatically every time the computer boots? What is the largest number of "speed access", "update check", "camera download" and whatever other background programs you have ever seen running? Of those, how many did you really need?

By: J.A. Watson

Read full story:
Annoying software: a rogues' gallery

Discussions

319762 319762

Eve of Distraction

Saturday 26 July 2008, 4:37 AM

1 comment

Vista Upgrade Blog

Microsoft's pre-modern message puts a...

Over at ZDNet.com, Ed Bott reports a first sighting of Microsoft's eagerly awaited $300 million ad campaign. Already the cause of much speculation, the consensus is that this will be... More

8 comments

A $40 CONSUMER-class router has create...

Believe it or not I don't work in IT, haven't for 7 years. Yes I work with Microsoft's Windows XP Embedded and as a result I have to know a lot about the OS, the kernal, Win API calls... More

Post a comment

Sick Puppy Redo

I generally follow a dispassionate investigative process when trying to discern what happened when a project goes bad. Although its a low priority item, it gets done simply because... More

Post a comment