Home arrow ASP arrow Page 3 - Front End XML For ASP Developers

Front End XML For ASP Developers

Yahoo are using XML for their orders, are you? Should you be? In this article Eugene sheds some light on XML from an ASP developers perspective...

Author Info:
By: Eugene Gilerson
Rating: 5 stars5 stars5 stars5 stars5 stars / 36
November 18, 2002
  1. · Front End XML For ASP Developers
  2. · Data Exchange
  3. · Configuration Files
  4. · There's a Bonus
  5. · Conclusion

print this article

Front End XML For ASP Developers - Configuration Files
(Page 3 of 5 )

As we see with most commercially available systems today, XML has become the format of choice for application configuration files. Take, for example, products like BEA WebLogic or the Microsoft .NET framework and you will find that both system-level and application-specific configuration data is stored in an XML format.

Along the same lines, we now see XML used for formatting configuration files in custom-built internal Web and client/server applications, often even replacing such widely used standard as ".ini" files.

Why XML then? Simple. Because it's both easy to read by humans -- and thanks to standard libraries available in all popular languages -- easy to parse within the code.

A good example of this happening is a situation when you need to persist your settings in an ASP application. In this case, using global.asa just isn't good enough application variables expire because of inactivity, and the data is lost. Let's take a look at an example when XML is used to build a typical configuration file and persist the server hit count tally.

The XML file itself looks very simple:

<?xml version="1.0"?>
<Application version="2.0">

The key to implementing this logic is to load the data into application variables in order to make it available on all pages across the application. This can be accomplished in the Application_onStart procedure of the global.asa file:

Sub Application_OnStart
Dim objXmlDom, xmlRoot

Set objXmlDom = CreateObject("Microsoft.XMLDOM")
objXmlDom.async = False
objXmlDom.Load Server.MapPath(".") & "\config.xml"

Set xmlRoot = objXmlDom.documentElement

Application("HitCount") = CInt(xmlRoot.childNodes(0).text)

Set xmlRoot = Nothing
Set objXmlDom = Nothing
End Sub

Then, in any page of the application, we can use standard ASP syntax to update the HitCount Application variable:

Application("HitCount") = Application("HitCount") + 1

The last piece of the puzzle is making sure that the value of the HitCount variable is saved to the XML file before IIS is unloaded from memory. This can be done in Application_OnEnd procedure of global.asa file, as shown below:

Sub Application_OnEnd
Dim objXmlDom, xmlRoot

Set objXmlDom = CreateObject("Microsoft.XMLDOM")
objXmlDom.async = False
objXmlDom.Load Server.MapPath(".") & "\config.xml"

Set xmlRoot = objXmlDom.documentElement

xmlRoot.childNodes(0).text = Application("HitCount")
objXmlDom.Save Server.MapPath(".") & "\config.xml"

Set xmlRoot = Nothing
Set objXmlDom = Nothing
End Sub

Formatting XML for presentation
In most systems today the key to information processing is its immediate availability over the web. So instead of parsing XML data and storing it in a temporary location (be it in memory, structured database or files on the hard drive), XSL templates are used to format XML data into HTML and present it to web clients right there and then.

XSL Stands For eXtensible Style Sheet Language
An XSL document is an XML-based template, which is used by an XML parser to format XML data into HTML documents. XSL syntax allows for such programming structures as loops and conditional statements, but is mostly geared towards formatting data for presentation rather than building business logic.

For example, the owner of a Yahoo store may need to review all orders before uploading them to database. Given XML in the earlier code example, it would be very easy to create an XSL style sheet that converts the XML into one big HTML table.

Keep in mind, the parser components still needs to be called in order to accomplish this task. Note that both XML and XSL files must first be loaded into parser components, and only then can the style sheet can be applied. For example:

Set objXml = Server.CreateObject("Microsoft.XMLDOM")
objXml.async = false
objXml.load(Server.MapPath(".") & "\YahooOrders.xml")

Set objXsl = Server.CreateObject("Microsoft.XMLDOM")
objXsl.async = false
objXsl.load(Server.MapPath(".") & "\YahooOrders.xsl")

'-- Apply stylesheet now
Response.Write objXml.transformNode(objXsl)

The reason for this structure is the case when one XML file can be formatted using different style sheets depending on user preferences. This facilitates the key concept of separating data and presentation layers of the application.
blog comments powered by Disqus

- Central Scoreboard with Flash and ASP
- Calorie Counter Using WAP and ASP
- Creating PGP-Encrypted E-Mails Using ASP
- Be My Guest in ASP
- Session Replacement in ASP
- Securing ASP Data Access Credentials Using t...
- The Not So Ordinary Address Book
- Adding and Displaying Data Easily via ASP an...
- Sending Email From a Form in ASP
- Adding Member Services in ASP
- Removing Unconfirmed Members
- Trapping HTTP 500.100 - Internal Server Error
- So Many Rows, So Little Time! - Case Study
- XDO: An XML Engine Class for Classic ASP
- Credit Card Fraud Prevention Using ASP and C...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials