Microsoft KB Archive/272177

= SAMPLE: Using OLEDB Templates to Retrieve XML Data Through XPath Query =

Article ID: 272177

Article Last Modified on 8/5/2004

-

APPLIES TO


 * Microsoft Data Access Components 2.6
 * Microsoft Data Access Components 2.7
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q272177



SUMMARY
The Oledbxpath.exe sample demonstrates how to use the ATL OLE DB consumer templates to extract an XML stream for a SQL Server 2000 Databases using an XPath query.



MORE INFORMATION
The following file is available for download from the Microsoft Download Center:

Oledbxpath.exe

Release Date: 9-29-2000

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 Oledbxpath.exe file contains the following files:

This samples demonstrates how to run an XPath query to output an XML stream. The sample shows how to run an XPath query by using the OLE DB ICommandText interface. Alternatively, you can do this by using the ICommandStreaminterface that contains an input stream which in turn contains the XPath query.

Additionally, it provides a mapping schema file that contains mapping information between elements and attributes in the XPath query and the tables and columns contained in the back-end SQL Server 2000 relational database management system (RDBMS). The CustomerOrder.xml mapping schema file provided with this sample contains information regarding a SQL JOIN between the Customers and Orders tables and their columns in terms of the Customers and CustOrder elements and their attributes. The sample does the following:   Sets the XPath query: m_szCommand = &quot;/Customers/CustOrder[@CustomerID=\&quot;ALFKI\&quot;]&quot;;   Configures the Microsoft OLE DB Provider for SQL Server (SQLOLEDB) property set DBPROPSET_SQLSERVERSTREAM, which is used for configuring the input stream: CDBPropSet propset(DBPROPSET_SQLSERVERSTREAM);   Sets the Base Path property to the folder containing the mapping schema file: propset.AddProperty(SSPROP_STREAM_BASEPATH, (LPCWSTR)m_path);   Sets the Mapping Schema property to point to CustomerOrder.xml: propset.AddProperty(SSPROP_STREAM_MAPPINGSCHEMA, OLESTR(&quot;CustomerOrder.xml&quot;));   Sets the dialect of ICommandText to DBGUID_XPATH: if(FAILED(hr = m_spCommand->QueryInterface(&pCommandText))) { printf(&quot;Failed to get an ICommandStream interface...\n&quot;); return hr; } if(FAILED(hr = pCommandText->SetCommandText(DBGUID_XPATH, T2COLE((LPCTSTR)m_szCommand)))) { printf(&quot;Failed to set command stream.\n&quot;); return hr; }                     Runs the ICommand::Execute method and retrieves the XML data in an output ISequentialStream interface: m_spCommand->Execute(NULL, IID_ISequentialStream, NULL, NULL, (IUnknown **) &pIXMLOutput ); </ol>

Steps to Run the Sample

 * 1) Create an empty Win32 console application.
 * 2) On the General tab of the Project/Settings dialog box, change the Microsoft Foundation Classes settings to Use MFC in a Static Library.
 * 3) Insert OLEDBXPath.cpp into the project.
 * 4) Copy CustomerOrder.xml into the project folder.
 * 5) Make sure that the project options point to the SQLOLEDB.H file that ships with Microsoft Data Access Components (MDAC) 2.6 SDK.
 * 6) Modify the connection string to refer to a valid SQL Server 2000 database.
 * 7) Compile and then run the application.

<div class="references_section">