Description: This sample demonstrates a simple shopping cart application. It allows a user to query the SQL Server Pubs sample database for a set of books. The application displays a tabular list of books that match her query, and presents a user interface that allows her to make purchase selections. The current set of books that the user wishes to purchase is placed inside of a shopping cart, the contents of which are also displayed in the applications user interface. The user can issue as many queries against the database as she wishes, and can add any number of books to her shopping cart. When she has completed her shopping trip, she can proceed to the checkout, where the shopping cart application will calculate her purchase totals on the server.
This sample demonstrates several interesting uses of XML. The first is as the means to encode hierarchical data streams. Most traditional RDBMS systems return tabular data sets. Unfortunately, tabular data sets are not the most efficient way to represent information that is acquired as the result of a one-to-many or a many-to-many SQL JOIN operation. XML, by its very nature, is very amenable towards the encoding of hierarchical data streams. In this sample, we will demonstrate the use of the hierarchical recordset feature of ADO 2.1, using the Microsoft Data Shape OLE DB provider. The second interesting use of XML is to dynamically create an XML document on the fly on the client. The dynamically created XML document is used to store the contents of the users shopping cart on the client. We ship the shopping cart XML document to the server at check out time.
This application is an example of a design pattern called a one-page-web application (for details see
The sample1.htm file contains a pair of
The btnAddToCart_onclick() function demonstrates copying nodes from one XML parser object to another. When the user decides to add a selection of books to her shopping cart, this method walks through all of the elements that have been checked on the list, and adds them to the shopping cart XML parser object.
The btnCheckout_onclick() function creates an instance of the XML HTTP Request object, and uses it to POST the XML-encoded shopping cart to the checkout.asp server-side function. This function simply calculates the total of all of the books in the users selection, and returns a simple XML-encoded document that contains the total price of all of the users selections in her shopping cart.
The runQueryJ.asp file contains the code that generates a hierarchical recordset. It takes as its input the XML-encoded request from the client. The request contains three parameters: the computer name of the SQL Server database, the database to use, and a string that represents the WHERE clause of the SQL query. The SQL query takes into consideration that there is a many-to-many relationship between books and book authors. It generates a hierarchical recordset that contains a list of books, and for each book the list of authors for that book. It then converts that list of books to an XML-encoded data stream and transmits that data back to the client.
Note that this sample must be manually copied to your web server. You can find the files that you need to copy in the ADOXML2\ADOXML2_Local subdirectory. To copy the source files to the web server, run the setup.cmd script in the ADOXML2 subdirectory. You must have the Windows Scripting Host installed to run this setup script.
This sample requires Internet Explorer 5.0 on the client, and Internet Information Server 4.0 on the server. The Microsoft Data Access Components SDK Version 2.1 must be installed on the server.
Note: This sample also requires the RequestExLib.RequestEx COM object, which can be found in the RequestExLib.dll. You can find a copy of this DLL under the Tools\bin directory. It needs to be registered first (run regsvr32 on the file). This COM object is used to ensure that we can read code from an HTTP POST request into an XML Parser object instance using either IIS 4.0 or IIS 5.0.
If you are running Windows 2000, the ASP scripts on the server will conditionally execute a different code path to take advantage of new features that are only available in the Microsoft Data Access Components SDK Version 2.5 and Internet Information Server 5.0.