Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

SAMPLE: How To Retrieve Relational Data Using OpenXML with ADO in Visual C++


View products that this article applies to.

This article was previously published under Q271775

↑ Back to the top


Summary

OpenXML.exe demonstrates how to retrieve an ADO Recordset from an input XML document by using the OpenXML feature in SQL Server 2000.

↑ Back to the top


More information

The following file is available for download from the Microsoft Download Center:
Release Date: 10-19-2001

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591� How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. The OpenXML.exe file contains the following files:

Collapse this tableExpand this table
File nameSize
EULA.txt2 KB
OpenXML.cpp6 KB
XMLDoc.xml1 KB


OpenXML.exe is a SQL Server 2000 extension to Transact-SQL that allows stored procedures to process XML and generate rowsets from the data for use by Transact-SQL statements. In this sample, an ADO client passes an XML document to a stored procedure. The stored procedure runs a SELECT statement, which generates a rowset. This rowset is then returned to the client as an ADO Recordset.

This sample creates a stored procedure named SP_OpenXML_Example on a SQL Server 2000 database and passes an XML document XMLDoc.xml to the stored procedure. The stored procedure processes the document using OpenXML and returns an ADO Recordset back to the client.

Additionally, the SP_OpenXML_Example stored procedure contains calls into the system stored procedures sp_xml_preparedocument and sp_xml_removedocument that load and unload the document from memory respectively. The SP_OpenXML_Example stored procedure is doing the following things:

  1. Runs the sp_xml_preparedocument system stored procedure to prepare the XML document for use by Transact-SQL statements.
  2. Uses the OpenXML-generated rowset in a query.
  3. Runs sp_xml_removedocument to remove the prepared XML document from memory.
For more details about the sp_xml_preparedocument and sp_xml_removedocument stored procedures or about OpenXML, refer to SQL Server 2000 Books OnLine.

Steps to Run the Sample

  1. Create an empty Win32 console application.
  2. Insert OpenXML.cpp into the project.
  3. From the Project menu, click Settings, and then click the C/C++ tab. In the Project Options dialog box, change /MLd to /MTd.
  4. Copy XMLDoc.xml into the project folder.
  5. Compile and then run the application.

↑ Back to the top


References

For additional information on XPATH query and XML, click the article numbers below to view the articles in the Microsoft Knowledge Base:
272177� SAMPLE: How to Retrieve XML Data Using an XPATH Query in ATL OLE DB
272185� SAMPLE: How to Retrieve Data Using a SQL XML Query in ATL OLE DB
271780� SAMPLE: How To Retrieve XML Data using a SQL XML Query with ADO in Visual C++
271782� SAMPLE: How To Retrieve XML Data Using an XPATH query with ADO in Visual C++
272180� SAMPLE: How to Retrieve XML Data Using a Template File with ADO in Visual C++
SQL Server 2000 Books OnLine

ADO 2.6 Documentation

↑ Back to the top


Keywords: kbdownload, kbfile, kbinfo, kbmsxmlnosweep, KB271775

↑ Back to the top

Article Info
Article ID : 271775
Revision : 8
Created on : 8/9/2004
Published on : 8/9/2004
Exists online : False
Views : 207