5,664,339 members and growing! (16,700 online)
Email Password   helpLost your password?
Web Development » ASP » General     Intermediate

Convert any Table into XML format & view it using XSL

By 'Anil' Radhakrishna

Convert any Table into XML format & view it using XSL
NT4, Win2K, Windows, ASP, Dev

Posted: 14 Jul 2002
Updated: 22 Jul 2002
Views: 66,500
Bookmarked: 31 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 2.07 Rating: 3.44 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 100.0%
4
0 votes, 0.0%
5

Introduction

This application allows you to convert a Recordset derived from a Table of any ADO and OLE-DB complaint Database into XML format and you can additionally view it using XSL. I have tested it out with Access and SQL Server but it should work fine with other Database Management Systems. It is more generic than an existing Microsoft KB article - Q281099: HOWTO: Use Active Server Pages to Dynamically Generate XML and also differs code-wise.

The user has to specify a DSN-less Connection string and a Table name pertaining to that database. The corresponding Recordset is converted to XML and this is displayed by a generic Extensible Stylesheet Language file. You can save this page as a .xml file. To keep the code snappy it is assumed that the DSN-less Connection string and the Table name are valid and no checking is done. Moreover special data types like Image, Binary are not supported.

A XML file generated by this app may look like this -

<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='generic.xsl'
version='1.0'?>
<xml>
<row CallID='CallID' ContactID='ContactID'
CallDate='CallDate' CallTime='CallTime'
Subject='Subject' Notes='Notes' />
<row CallID='1' ContactID='1' CallDate='11/21/1994'
CallTime='12:05:00 PM' Subject='Suite of coffees.'
Notes='Spoke to Janet about NWIND carrying a coffee
collection designed by us.' />
<row CallID='2' ContactID='1' CallDate='12/13/1994'
CallTime='12:45:00 PM' Subject='Pricing for proposed
suite.' Notes='Too high - should wait and see if Janet
comes around.' />
</xml>
You may remove lines 2 and 3 if you are interested only in the xml file or tweak the code to prevent them from appearing at all. You can use the FileSystemObject to create and store XML and their equivalent XSL files automatically on your machine.

XML has become the lingua-franca of the Internet. RDBMS's like Oracle and SQL Server have built-in XML features. To retrieve rows in XML format using SQL Server 2000,you can use the SELECT query with the FOR clause.

Steps to run the app -

  1. The zipped file contains 3 files xmily.html, xmile.asp and generic.xsl. Create a new folder named xmile within the folder that contains the content for your default Web site. This is the :\InetPub\WWWRoot folder by default. Unzip xmile.zip to this folder.
  2. You'll need IIS or PWS to first call xmile.html using http like this-
    http://localhost/xmile/xmily.html
  3. Type in a DSN-less Connection string to connect to a DBMS and a Table name. The XML content opens in a new window as a HTML table with the help of the XSL file, generic.xsl.

Source Code

  • xmily.html allows user to submit Connection String and Table name
  • generic.xsl displays the recordset converted to XMLformat as a HTML table.
  • xmile.asp handles the actual conversion of recordset info into XML.

Useful Links

You can find a nice compilation of Connection Strings here


License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

'Anil' Radhakrishna


'Anil' Radhakrishna is a seasoned developer and a Microsoft MVP (ASP/ASP.NET). He blogs his little discoveries and Web development tips, tricks and trivia quite regularly. You can find some of his unusual code samples & snippets at his Code Gallery.

Occupation: Web Developer
Location: India India

Other popular ASP articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 4 of 4 (Total in Forum: 4) (Refresh)FirstPrevNext
GeneralFileSystemObjectmemberMember 37070531:35 7 Apr '08  
GeneralI don't correct output [modified]memberyogeshbhandare23:56 25 Mar '07  
GeneralHmm...memberShog911:30 15 Jul '02  
GeneralRe: Hmm...editorAndrew Peace13:15 15 Jul '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 Jul 2002
Editor: Nishant Sivakumar
Copyright 2002 by 'Anil' Radhakrishna
Everything else Copyright © CodeProject, 1999-2008
Web12 | Advertise on the Code Project