ASP
  Home arrow ASP arrow Page 4 - XML Strengths and Weaknesses with DOM, ASP...
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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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

XML Strengths and Weaknesses with DOM, ASP and XSL
By: Nakul Goyal
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 17
    2002-03-05

    Table of Contents:
  • XML Strengths and Weaknesses with DOM, ASP and XSL
  • XML Definitions
  • XML and DOM
  • Our XML example explained
  • 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


    XML Strengths and Weaknesses with DOM, ASP and XSL - Our XML example explained


    (Page 4 of 5 )

    Firstly, we connect to SQL Server 2000 using a system DSN. The DSN is called "pubs", and you should create the DSN using control panel. It should connect to your SQL server, more specifically to its pubs database. We instantiate an ADO connection object, passing in the DSN to its open method:

    'Open database connection

    Set conn = Server.CreateObject("ADODB.Connection")

    dsn = "DSN=pubs;UID=sa;PWD="

    conn.Open dsn


    Once we're connect to our database, we create a new XML document and assign it a root element called "Hi-Tech". We then proceed to retrieve a recordset from the authors table of our pubs database:

    If (xmldoc.childNodes.length = 0) Then

    ' Build the XML document

    Set root = xmldoc.createNode("element", "Hi-Tech", "")

    xmldoc.appendChild (root)

    ' Queries the database for customer data

    Sql = "select au_lname,au_fname,au_id from authors"

    Set rs = conn.Execute(Sql)

    rs.MoveFirst


    We then loop through each record in the recordset, appending its title, titleID and royalty fields to the XML document that we created earlier. We use the createNode and appendChild methods to do so:

    Set inode = xmldoc.createNode("element", "Titles", "")

    onode.appendChild (inode)

    Set child = xmldoc.createNode("element", "TitleId", "")

    child.Text = rs2.fields(0)

    inode.appendChild (child)

    Set child = xmldoc.createNode("element", "royalty", "")

    child.Text = rs2.fields(1)

    inode.appendChild (child)


    Once we've retrieved each of the records from the recordset and appended them to our XML document, we save the XML document to our local machine using MSXML's save method:

    xmldoc.save server.mappath("saved.xml")

    We're now at the point where we have an XML file called saved.xml, as well as the style sheet that's included in the support material for this article, called saved.xml. We instantiate a new XMLDOM object for each of these files, calling the transformNode method of the XML DOM object with a reference to the XML DOM object that contains the XSL file:

    sourceFile = Server.MapPath("saved.xml")

    styleFile = Server.MapPath("saved.xsl")

    set source = Server.CreateObject("Microsoft.XMLDOM")

    source.async = false

    source.load(sourceFile)

    set style = Server.CreateObject("Microsoft.XMLDOM")

    style.async = false

    style.load(styleFile)


    Lastly, we use Response.Write to output the transformed XML to the browser:

    Response.Write source.transformNode(style)

    More ASP Articles
    More By Nakul Goyal


     

    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-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway