MDAC Technical Articles

XML

OLE DB rowsets are self-describing objects that contain data and metadata, created by executing commands against data stores. Because of its self-describing nature, rowset information can be easily represented in XML. Therefore, XML is supported as a streaming and persisting format for rowsets. This opens up the use of rowsets to non-COM platforms: If XML-represented structured data can be generated from there, it can be translated into rowsets on other machines and vice versa. This also allows ADO Recordset objects to be transmitted over HTTP as part of standard HTML text.

The OLE DB Persistence Provider can be used to save a recordset in XML format to any object that implements the IStream interface, such as the Active Server Pages Response object. This feature eliminates the inefficient step of saving the XML to a file on a disk and then sending that file to the Response object.

The following is a snippet of an XML stream representing a rowset. The rowset was generated from the sample Pubs database in Microsoft SQL Server™ 7.0, using the following command:

SELECT title, au_lname, price, ytd_sales FROM titleview

Following is the XML as generated by the Persistence Provider (in MDAC 2.5):

<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
   xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
   xmlns:rs='urn:schemas-microsoft-com:rowset'
   xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
   <s:ElementType name='row' content='eltOnly' rs:CommandTimeout='30'>
      <s:AttributeType name='title' rs:number='1' rs:writeunknown='true'>
         <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='80' 
               rs:maybenull='false'/>
      </s:AttributeType>
      <s:AttributeType name='au_lname' rs:number='2' 
            rs:writeunknown='true'>
         <s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='40' 
               rs:maybenull='false'/>
      </s:AttributeType>
      <s:AttributeType name='price' rs:number='3' rs:nullable='true' 
            rs:writeunknown='true'>
         <s:datatype dt:type='i8' rs:dbtype='currency' dt:maxLength='8' 
               rs:precision='19' rs:fixedlength='true'/>
      </s:AttributeType>
      <s:AttributeType name='ytd_sales' rs:number='4' rs:nullable='true' 
            rs:writeunknown='true'>
         <s:datatype dt:type='int' dt:maxLength='4' rs:precision='10' 
               rs:fixedlength='true'/>
      </s:AttributeType>
      <s:extends type='rs:rowbase'/>
   </s:ElementType>
</s:Schema>
<rs:data>
   <z:row title='You Can Combat Computer Stress!' au_lname='Green' 
         price='2.99' ytd_sales='18722'/>
   <z:row title='The Gourmet Microwave' au_lname='DeFrance' price='2.99' 
         ytd_sales='22246'/>
   <z:row title='The Gourmet Microwave' au_lname='Ringer' price='2.99' 
         ytd_sales='22246'/>
   <z:row title='Fifty Years in Buckingham Palace Kitchens' 
         au_lname='Blotchet-Halls' price='11.95' ytd_sales='15096'/>
</rs:data>
</xml>

For more information, see the technical article "Saving ADO Recordsets in XML Format."