ASP
  Home arrow ASP arrow Page 3 - Front End XML For ASP Developers
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Front End XML For ASP Developers
By: Eugene Gilerson
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2002-11-18

    Table of Contents:
  • Front End XML For ASP Developers
  • Data Exchange
  • Configuration Files
  • There's a Bonus
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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">
    <HitCount>5</HitCount>
    </Application>


    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.Lock
    Application("HitCount") = Application("HitCount") + 1
    Application.UnLock


    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.

    More ASP Articles
    More By Eugene Gilerson


     

    ASP ARTICLES

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







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek