Home arrow ASP arrow Page 4 - XML Strengths and Weaknesses with DOM, ASP and XSL
ASP

XML Strengths and Weaknesses with DOM, ASP and XSL


Since the inception of XML, many developers have wondered why they need XML and how they can use XML to their benefit. In this article Nakul looks at some of the terminology that comes with using XML and its related technologies, as well as how to create and transform XML documents with ASP and XSL using Microsoft's MSXML parser.

Author Info:
By: Nakul Goyal
Rating: 5 stars5 stars5 stars5 stars5 stars / 42
March 05, 2002
TABLE OF CONTENTS:
  1. · XML Strengths and Weaknesses with DOM, ASP and XSL
  2. · XML Definitions
  3. · XML and DOM
  4. · Our XML example explained
  5. · Conclusion

print this article
SEARCH DEVARTICLES

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)
blog comments powered by Disqus
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...

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 
Support 

Developer Shed Affiliates

 




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