Implement a flexible shopping basket with XML and ASP

Daily Newsletters

Sign up to ZDNet UK's daily newsletter.

ANALYSIS
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.

Talkback

The links to the listings do not appear to work. They take you to a general page on builder.com

via Facebook 8 August, 2003 07:13
Reply

Sorry about that. Try the links on the original article (http://builder.com.com/5100-6389-5035160.html?tag=sc#Listing%20A).

via Facebook 29 October, 2003 14:14
Reply

Post your comment

In order to post a comment you need to be registered and logged in.

You can also log in with Facebook. Log in or create your ZDNet UK account below

  • Login

Will not be displayed with your comment

By signing up for this service, you indicate that you agree to our Terms and Conditions and have read and understood our Privacy Policy. Questions about membership? Find the answers in the Community FAQ

Get ZDNet UK's daily newsletter

Enter your email address to sign up

ZDNet UK Live

Moley

@GrueMaster. I prefer horses for courses rather than one size fits all. I, and I suspect most other computer users, do not really wish to have...

2 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
greycynic

The product that scares me every time I have to use it is the Office 2007 version of Excel. The first bug that I found was applying the median...

2 hours ago by greycynic on Ten flawed products that derail productivity
GrueMaster

Nice review and very informative. One thing I'd like to add (in reply to whs001's 1st question), the main reason to have the same interface from...

3 hours ago by GrueMaster on A tale of two distros: Ubuntu and Linux Mint
Frederick Wrigley

I'be been using Mint 12 since the RC came out, and I am far more happy with the Cinnamon, the Mate, and, yes (with extensions), theGnome 3...

4 hours ago by Frederick Wrigley via Facebook on A tale of two distros: Ubuntu and Linux Mint
bdantas

Excellent article. One small correction, though--although a fresh installation of Linux Mint 12 will, indeed, provide the user with a version of...

5 hours ago by bdantas on A tale of two distros: Ubuntu and Linux Mint
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

5 hours ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Alan Ralph

In related news, the ISPs club together to get the members of the Home Affairs Select Committee (ya goofed on that part, ZDNet UK) copies of "The...

6 hours ago by Alan Ralph via Facebook on MPs urge ISPs to take down terrorist material
Moley

For Gnome 2 die-hards, it is possible to add icons to the bottom panel (or top top panel, if you prefer) which provide the exact Gnome 2...

6 hours ago by Moley on A tale of two distros: Ubuntu and Linux Mint
ramwellian

Your comments would seem pretty naive and immature. Your 'solution' appears to be, "gee, let's all just give in to the hackers and give them...

6 hours ago by ramwellian on Cloud computing security: no more oxymoron?
BugStalker

"Interesting thought ... If you installed Win7 as a dual boot on a machine that previously only had Linux, and it wrecked your Linux installation,...

7 hours ago by BugStalker on Windows 7 Declares War on GRUB
whs001

This is an excellent summary of Ubuntu and Mint and the interface differences between them. Most such articles take a very partisan position for...

7 hours ago by whs001 on A tale of two distros: Ubuntu and Linux Mint
Moley

@ewallace. Not so clear. Anyone can obtain the text, for example from here http://www.ustr.gov/webfm_send/2379. I support ACTA so long as it and...

7 hours ago by Moley on ACTA: Facts, misconceptions and questions
45283

I think WinRT is fantastic. I just wish it was an option for people that didn't want to go through Microsoft's App Store with its attendant...

10 hours ago by 45283 on Why Windows 8 needs architectural hygiene for WOA
Burn-IT

Nine people? £30m? Who's back pocket is that lot going in? And IF they say it is for new buildings, what about all the ones the government has...

11 hours ago by Burn-IT on Police set to launch three £30m e-crime hubs
ewallace

Just to be clear, nobody knows what is in the text of ACTA, here is a photograph of the text of ACTA http://twitpic.com/8h9iju as submitted to the...

11 hours ago by ewallace on ACTA: Facts, misconceptions and questions
fgvrg56

Unfortunately main issue is that ASUS is refusing to accept that they make some mistake on this version of asus Transformer prime. 1 - GPS sensor...

13 hours ago by fgvrg56 on Asus Eee Pad Transformer Prime Wi-Fi & GPS problems?
Ben Woods

@Marcus A fair question. Just talked with Archos which said it was working on an announcement for next week....

14 hours ago by Ben Woods on Archos confirms G9 Ice Cream Sandwich update schedule
Marcus Karlsson

Any update on this, considering the claimed "first week of February"?

15 hours ago by Marcus Karlsson via Facebook on Archos confirms G9 Ice Cream Sandwich update schedule
apexwm

Bill Goodrich : Just as al_langevin pointed out, with Windows Server 2008 there is no Services for Macintosh anymore. It's gone, not available....

23 hours ago by apexwm on Windows Server 2008 drops the ball for Mac compatibility
txtrainguy

Replying to an old topic that I'm currently facing with my CEO (who is on a Mac). Our servers are primarily Windows Servers, office is about...

1 day ago by txtrainguy on Windows Server 2008 drops the ball for Mac compatibility