Microsoft KB Archive/271772

= How To Access Hierarchical XML Data with the XML OLE DB Simple Provider =

Article ID: 271772

Article Last Modified on 6/29/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 Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q271772



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

This article has step-by-step instructions to set up a Visual Basic 6.0 sample that demonstrate how to access hierarchical data that is contained in an XML document with the XML OSP.



MORE INFORMATION
Run the following steps to set up and test a Visual Basic sample that demonstrates how to use the OLE DB Simple provider for XML:   Open an empty file in Microsoft Notepad. Copy and paste the following XML into the file and save it as portfolio.xml: MSFT $66.00            Microsoft Corporation http://www.microsoft.com AAPL $110.00            Apple Computer, Inc.             http://www.apple.com DELL $50.00            Dell Corporation http://www.dell.com INTC $136.00            Intel Corporation http://www.intel.com  Open a Standard EXE project in Visual Basic. Form1 is created by default. Add a Project reference to the Microsoft ActiveX Data Objects 2.6 library. Add a CommandButton to Form1.  Copy and paste the following code in the form module and specify the path to portfolio.xml in the adoRS.Open statement: Private Sub Command1_Click Dim adoRS As ADODB.Recordset Set adoRS = New ADODB.Recordset ' Set up the Connection adoRS.ActiveConnection = &quot;Provider=MSDAOSP; Data Source=MSXML2.DSOControl.2.6;&quot; ' Open the XML source adoRS.Open &quot;&quot; On Error GoTo RecError printtbl adoRS, 0 GoTo Bye RecError: Debug.Print Err.Number & &quot;: &quot; & Err.Description If adoRS.State = adStateOpen Then For Each Col In adoRS.Fields Debug.Print Col.Name & &quot;: &quot; & Col.Status '  Error Status Next Col End If Bye: If adoRS.State = adStateOpen Then adoRS.Close End If   Set adoRS = Nothing End Sub

' Function to recursively retrieve the data Sub printtbl(rs, indent) On Error Resume Next Dim rsChild As ADODB.Recordset Dim Col As ADODB.Field 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 Debug.Print Space(indent) & Col.Name & &quot;: &quot; & Col.Value, Else Debug.Print ' Retrieve the Child recordset Set rsChild = Col.Value rsChild.MoveFirst If Err Then MsgBox Error printtbl rsChild, indent + 4 rsChild.Close Set rsChild = Nothing End If       End If        Next Debug.Print rs.MoveNext Wend End Sub  Save the project and run it. Click the CommandButton on Form1 to run the Visual Basic ActiveX Data Objects (ADO) code that uses the XML OSP to load the data that is in portfolio.xml into an ADO recordset object. The code then calls the printtbl subprocedure and passes the loaded ADO recordset as an input parameter to it. The code in the printtbl subprocedure loops through the recordset and prints its contents to the debug window. Press the CTRL-G keys to view the debug window if it is not visible in the Visual Basic integrated development environment (IDE).</li></ol>

Additional query words: MSDAOSP MSXML2.DSOControl.2.6 portfolio

Keywords: kbhowto kbmsxmlnosweep KB271772

-

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

© Microsoft Corporation. All rights reserved.