XML
  Home arrow XML arrow Page 4 - XML Integration with ADO
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
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? 
XML

XML Integration with ADO
By: Gayathri Gokul
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 12
    2004-04-05

    Table of Contents:
  • XML Integration with ADO
  • XML Data Simplified
  • Easy as 1,2,3
  • Saving Recordsets as XML

  • 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 Integration with ADO - Saving Recordsets as XML


    (Page 4 of 4 )

    Using ADO we can very easily generate XML recordsets by making use of  “Save” method of the Recordset object, and specifying the format as “adPersistXML”. This feature isn’t new to ADO 2.5, but what is novel is the ability to persist hierarchical recordsets, and to directly persist them into other objects, such as DOM objects and streams.

    This opens up any number of possibilities for manipulation and transfer of data, since we are no longer restricted to creating text files containing XML data. Why is this such good news? Well, as programmers we want two major things to work without hassle:

    • An easy way to generate data.
    • A fast way to transfer data.

    Creating text files is easy, but slow. It involves tedious work like writing the file to the disk, and then reading the data back in to manipulate it. What we are trying to reach ultimately is finding out ways to eliminate as much as the slow processing as possible. If we could derive at anything that makes our life easier as programmer or developers has to be good thing.

    Persisting ADO Recordsets to XML Files

    The simplest method of converting ADO recordset to XML is a method that’s been in previous version of ADO. Just included this code for reference.

    <pre><blockquote><font face=verdana size=1>
    rs.Authors.Save  “c:tempauthors.xml”
    </font></blockquote></pre>

    Persisting ADO Recordsets to a Stream

    A Stream is simply a block of data in memory, which is not processed in any way. ADO 2.5 introduced the new Stream object, and this can be the way for saving a recordset.


    Set rsAuthors Server.CreateObject(ADOBD.Recordset”);
    Set stmAuthors 
    Server.CreateObject(ADOBD.Stream”);
    rsAuthors.Open “authors”strConn
    rsAuthors
    .Save  stmAuthorsadpersistXML

    We now have a Stream object containing the XML recordset, and we can use the stream methods and properties to manipulate data. Let’s say we want to extract the XML into a string using the ReadText method, we could do so as follows:


    strXMLAuthors stmAuthors.ReadText.

    At this stage strXMLAuthors contains the complete XML recordset including the schema.

    Persisting ADO Recordsets to the Response Object

    We can think of streams as something more literal. The dictionary defines a stream as "a flow or moving succession of anything." So, let's think of a stream of data as a flow of data from one place to another. Keeping this in mind, let’s imagine we are sending this data from our ASP page to browser-that’s a flow of data, too.

    Just how do we do this?  We do so by using a new feature of the Response object, which has built in support for Streams. So it is like pouring our data into one end of the stream, and having it end up at the other end. On one end is the Response Object, and the other end is the browser. All this is made feasible because of the integrated support for streams in the Response object:


    rsAuthors.Save ResponseadPersistXML

    This saves the recordset as XML directly into the response object. The Response object in turn handles the sending of data to the browser. Pretty cool!

    Conclusion

    Today we have learned about:

    1. binding hierarchical XML data, such as those in data shaped recordsets
    2. enumerated the working of XML data with Data Island
    3. persisting ADO recordsets to XML files as well as streams
    4. a easier way of Persisting ADO recordsets to Response objects.

    Each one has its own advantages over the other. But there is a much easier way to do this, which is Persisting ADO Recordsets to DOM object, which we will be covering in depth in the next part of the tutorial.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT