Microsoft KB Archive/272270

= How To Retrieve XML Data in ASP with the XML OLE-DB Simple Provider =

Article ID: 272270

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft ActiveX Data Objects 2.6
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7
 * Microsoft Active Server Pages 4.0
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q272270



SUMMARY
This article includes step-by-step instructions to set up an ASP client that demonstrates the use of the OLEDB Simple Provider for XML to access hierarchical XML data.

The OLE-DB Simple Provider for XML (XML OSP) can be used to load data in an XML document into a read-only ADO recordset. The data is then read and accessed by using the standard methods of the ADO Recordset object. This provider can be used to provide a different method of working with hierarchical data that is contained in XML documents.



MORE INFORMATION
Run the following steps in sequence to set up and test an ASP page that uses the XML OSP to access hierarchical data that is stored in an XML document:   Open a new file in Microsoft Notepad. Copy and paste the following code into it, and then save the file as TestOSP.asp in an IIS virtual directory that has permissions to run scripts: <%@ Language=VBScript %>

<%

Dim adoRS      'ADODB.Recordset Set adoRS = CreateObject(&quot;ADODB.Recordset&quot;) ' Set up the Connection adoRS.ActiveConnection = &quot;Provider=MSDAOSP; Data Source=MSXML2.DSOControl.2.6;&quot; ' Open the XML source adoRS.Open Server.MapPath(&quot;.&quot;) & &quot;\portfolio.xml&quot; printtbl adoRS, 0 If adoRS.State = adStateOpen Then adoRS.Close End If   Set adoRS = Nothing Response.End

' Function to recurcusively retrieve the data Sub printtbl(rs, indent) Dim rsChild        'ADODB.Recordset Dim Col            'ADODB.Field set rsChild = Server.CreateObject(&quot;ADODB.Recordset&quot;) While rs.EOF <> True For Each Col In rs.Fields If Col.Name <> &quot;$Text&quot; Then  ' $Text to be ignored If Col.Type <> adChapter Then ' Output the non-chaptered column Response.Write( String((indent),&quot; &quot; ) & Col.Name & &quot;: &quot; & Col.Value ) Else Response.Write(&quot; &quot;) ' Retrieve the Child recordset Set rsChild = Col.Value rsChild.MoveFirst If Err Then Response.write(&quot;Error: &quot; & Error ) Response.end end if                        printtbl rsChild, indent + 4 rsChild.Close Set rsChild = Nothing End If           End If        Next Response.Write( &quot; &quot;) rs.MoveNext Wend End Sub

%>                     The code in the preceding ASP file uses the OLEDB Simple Provider for XML to load data from an XML file named portfolio.xml to an ADO Recordset object. Open a new file in Notepad, and copy and paste the following XML into it. Save the file as portfolio.xml in the IIS virtual directory where you saved TestOSP.asp: CTS $66.00            Contoso Pharmaceuticals http://www.contoso.com FAB $110.00            Fabrikam, Inc http://www.fabricam.com PRO $50.00            Proseware, Inc http://www.proseware.com WWI $136.00            Wide World Importers http://www.worldwideimporters.com

 Browse to TestOSP.asp with Internet Explorer, and note that the data in portfolio.xml are displayed as required. The code in the ASP uses the XML OSP to load the XML data into an ADO Recordset, and then loops through the records in the recordset and writes out the values in the fields to the ASP Response Object.

Additional query words: MSDAOSP MSXML2.DSOControl.2.6 IE

Keywords: kbhowto KB272270

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.