When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Saturday, June 10, 2000

Converting Hierarchical Recordsets Into XML
By Richard Chisholm


Introduction:
This is the first of a series of articles I am writing that deals with using XML and the latest in XSLT technology to create a dynamic web application. My tentative plan for these articles are the following:

    - continued -

    1.) Create an XML document by converting data shaped recordsets with a recursive component.
    2.) Getting a more customized XML document by tweaking the SQL statement and the code for the component. [Read the Article!]
    3.) Using XSLT to get a viewable HTML interface in IE5. [Read the Article!]
    4.) A case study using XSLT to create an application that dynamically filters and sorts the XML data.

That may seem like a lot, but that's because there is a whole lot to cover. These articles are designed for ASP programmers with limited XML/XSLT experience, so if you are already familiar with some of this bare with me. I don't think most ASP developers have gone too far in XML, but you can do some really slick things with it, some of which you'll see here. To brush up on your XML, be sure to check out the XML Section on 4Guys!

For parts 1 and 2, you will need IE5 (with the 2.0 MSXML parser), and Visual Basic 6 if you want to edit the source yourself. For parts 3 and 4, you will need IE5 and at least the March preview release for MSXML3. This can be found at http://msdn.microsoft.com/downloads/webtechnology/xml/msxml.asp and you may want to visit the news group news://msnews.microsoft.com/microsoft.public.xml.msxml-webrelease if you have problems getting it to work properly. I found a nifty script that tests if your installation was performed correctly, as well as the info to get MSXML3 working. For the record, the component was developed and tested on a NT Workstation with the IE5 MSXML processor, while the XSLT used in parts 3 and 4 was created on a Win98 machine loaded with IE 5.01 and the March release of MSXML3, using the Athens XML Editor.

Part I: Converting Hierarchical Recordsets into XML
XML can be a very powerful too for ASP programmers. Although Microsoft has enabled ASP & VB programmers to save recordsets in XML format quickly and easily through the ADO Save command, doing so has several shortcomings. First, all the fields in the recordset are saved as attributes, making the document difficult to read and any XSL transformation can become overly complicated. Second, you cannot specify the tag names you would like to use, meaning your data can become harder to manipulate and understand (the opposite of what XML is intended for!). To see what I mean, take a look at this XML file created with the ADO adPersistXML method. It is in text format for those without IE5.

However, if you have similar data in different tables with different field names, instead of having to write multiple XSL documents, it would be easier if you could create nested, generic tag names such as <product> or <sport> and use an attribute like name= or value= to assign your data. This becomes an important issue when designing efficient style sheets. Third, and most importantly for this exercise, if you want to use data shaping and create hierarchical recordsets, you cannot use the Save method because ADO doesn't seem to know how to handle the child recordset field.

To solve these problems, I wrote a COM component that converts shaped recordsets into an XML document that uses a recursive function to generate the XML. It takes three parameters, and the whole program can be easily customized to create the type of XML document you require. The beauty of this component is in its simplicity: you can transform basic and complex database queries into XML with very little hassle. And by the end of this article, we will have an XML document that is much easier to read than the ADO method.

Wait, I can hear you ask, why should we use hierarchical (or data shaped) recordsets? The advantage of using them in this case is that your data comes out in a format much like most XML documents: with nested, parent-child relationships that define the structure of the data. Because this component is recursive, the structure of the XML will be entirely dependent on the structure of your SQL statement. This way, you can use the component to build different data structures simply by changing the SQL statement. For now you'll have to take my word for it, but in the next article I will show how a simple change to the SQL statement can produce a major change in the structure of the XML document. Additionally, because your data already has a discernable structure, the component spends less time (i.e. there are fewer lines of code, doesn't do a lot of detecting, and it runs faster) transforming the data.

In my tests, this component created parent->child->g-child->gg-child, as well as siblings of each, with no hassle. There is one snag however. Because in this example we want to create generic tag names using a recursive function, we need to have those values stored somewhere, in this case an array. Then when the function is called the proper numeric value is passed. I am going to assume basic knowledge of creating and using components, and skip right on to the code. Don't worry, the methods in the XML DOM are easy to understand even for those who have never seen them.

  • Read Part 2 of "Converting Hierarchical Recordsets into XML"


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES