Using XML To Supercharge Website Performance

Step 2: Run the Install Script

During this step we will create the necessary tables and stored procedures for this example. With query analyzer, open the file named “install.sql”, which is included in the download. Once the file is loaded into query analyzer, press F5 to execute the script. This will create a ‘CATEGORIES’ table. It will also populate the categories table with data and create two stored procedures. 

The install script has also created a stored procedure named ‘Categories_GetAll’, which returns a listing of all of the categories. Remember, this is the stored procedure that was being executed every time a page was loaded, which means you will not have to create this stored procedure since it is already in existence. The results of this stored procedure are what will be converted into an XML document. 

The second stored procedure is what will be executed at a specified interval. This second procedure is responsible for creating the component and calling the ‘CreateXMLDoc’ method of the object with the necessary parameters. 

The last part of the install script will create the job, which we will configure during the next step.

Step 3: Configure the Job

After executing the install script, you should have a job named “CREATE XML JOB – PLEASE CONFIGURE.” You can navigate to the job by connecting to the database, and you should see a tree view containing Databases, Data Transformation Services, Management, etc. Expand the Management node, and then expand the SQL Server Agent node. Click on the Job node and, in the right pane, right click on the job named “CREATE XML JOB – PLEASE CONFIGURE” and choose properties. Feel free to rename the job, and then click on the “Steps” tab, and edit the first step. This step executes the stored procedure that calls a method of the object. For each XML document that needs to be created, you will need to create a different job. We can reuse the stored procedure by passing in parameters to the stored procedure, which in return passes the same parameters into the object. We pass the following into the stored procedure through the job:

  • @ConnStr – A Connection string.
  • @SQL – The SQL that returns the record set that will be converted into an XML document.
  • @RootName – The root name for the XML document.
  • @SaveToPath – The path where the resulting XML document will be saved.

The job created by the install script already has examples of each value being passed in. Simply edit the values it passes. You can now configure the job in numerous ways. From this point on, you should create a schedule for the job, and have it notify an operator when it fails.

Step 4: Create An XSL Document Template Based on our XML Document

You should now have an XML document which is being created at regular intervals. If so, our next task is to create an XSL page that will provide a template as to how our XML will be outputted as HTML. There are tomes on XSL; nonetheless, a few simple explanations should suffice for this example. 

Open the file named categories.xsl included in the download. This XSL document is based on the categories.xml document. It will create a HTML table with two columns: category id and category name. The XSL processor takes the XML content and creates the presentation HTML by matching on templates in your XML document and looping through each node. Throughout each iteration of the loop the XSL processor selects the value(s) and builds the HTML document.

Take a look at the following code: <xsl:apply-templates select=”//categories”/>. It is important to note that “categories” is the root name we passed into the object. In the next step, we will place a line of code in your ASP document that will call a function that tells the processor to take the XML and XSL documents and create the HTML.

Step 5: Add A Few Lines of Code, and We’re Finished!

For this step, we simply need to remove our old code, add an include file to our ASP page, and call a function. First, make a backup copy of your current ASP page. Once you have done so, remove the old code that created and displayed the HTML. Only you know how to do this, but to see a solution that is not using this example, open the file named ‘NoXML.asp,’ and open ‘UsingXML.asp’ to see an example page using this solution.

Once you have removed the necessary code, add the include file XMLUtil.asp. The Include statement should be ‘<!– #include file=”include/XMLUtil.asp”–>.” This include file contains the necessary XML functions to transform your XML document using your XSL document. Now, we can simply add one line that calls the function with the path to the XML document and the path to the XSL document, and we are finished! The following code will suffice:

<% = TransformXML(“xml/categories.xml”, “xsl/categories.xsl” ) %>

That’s it! Hopefully this article will help you drastically increase your website’s performance. I didn’t go into as much detail as I could have, since this article is mainly focused on SHOWING you the big picture of how you can use XML for performance boosts. If you are unclear as to how the backend of this solution works, simply dive into the examples. This is the only way to get a full understanding of how this solution works. 

Please e-mail me to let me know how I can make this article easier to understand or with any errors you encounter when running the example on your current hardware and software configuration.

Published with the express, written permission of the author. Copyright 2001 Justin Gunther.


Leave a comment

Your email address will not be published.