Help and Support
 

powered byLive Search

SAMPLE: How To Retrieve XML Data Using an XPath Query with ADO in Visual C++

Article ID:271782
Last Review:April 18, 2006
Revision:5.4
This article was previously published under Q271782
On This Page

SUMMARY

XPath.exe demonstrates how to extract an XML stream from a SQL Server 2000 database by using an XPath query and ADO in Visual C++.

Back to the top

MORE INFORMATION

The following file is available for download from the Microsoft Download Center:
XPath.exe (http://download.microsoft.com/download/mdac26/utility/2.8/win98/en-us/xpath.exe)
Release Date: 10-04-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 (http://support.microsoft.com/kb/119591/EN-US/) 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 XPath.exe file contains the following files:

File nameSize
EULA.txt2 KB
AdoHeader.h1 KB
CustomerOrder.xml2 KB
ReadMe.txt1 KB
resource.h1 KB
StdAfx.cpp1 KB
StdAfx.h1 KB
XPath.cpp3 KB
XPath.dsp5 KB
XPath.dsw1 KB
XPath.h2 KB
XPath.rc5 KB
XPathDlg.cpp7 KB
XPathDlg.h2 KB
\Res\XPath.ico2 KB
\Res\XPath.rc22 KB

This sample demonstrates how to run an XPath query to output an XML stream. The sample shows how to configure an ADO Command object to run an XPath query by using the Command object's CommandText property. Alternatively, you can do this by using the CommandStream property and an input Stream as well.

Additionally, the sample 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 about a SQL JOIN between the Customers and Orders tables and their columns in terms of the Customers and CustOrder elements and their attributes. All the tables are from the Northwind sample database in SQL Server 2000.

The sample does the following:
1.Sets up a connection to a valid SQL Server 2000 database:

Note uid <user name> must have the appropriate permissions to perform these operations on the database.
_bstr_t m_Conn("PROVIDER=SQLOLEDB.1;Server=SQL2000Srv;Database=Northwind;uid=<user name>;pwd=<strong password>;");
					
2.Assigns the XPath globally unique identifier (GUID) to the ADO Command object's Dialect property:
hr = cmd->Properties->Item[L"Mapping Schema"]- >put_Value(_variant_t(L"\\CustomerOrder.xml")); 
					
3.Sets the ADO Command object's Mapping Schema property to point to the mapping schema file CustomerOrder.xml:
hr = cmd->Properties->Item[L"Mapping Schema"]->put_Value(_variant_t(L"C:\\MySchemaFilePath\\CustomerOrder.xml"));
					
4.Sets the ADO Command object's Output Stream property to an ADO Stream for retrieving the XML data:
hr = cmd->Properties->Item[L"Output Stream"]->put_Value(_variant_t((IDispatch*) strm));
					
5.Sets the Command object's CommandText property to the XPath query:
// Default XPATH Query is -
// m_XPathIn = L"/Customers/CustOrder[@CustomerID=\"ALFKI\"]";
hr = cmd->put_CommandText(_bstr_t(m_XPathIn ));
					
6.Runs the Command by using the adExecuteStream enumeration:
hr = cmd->Execute(&vra,&vtEmpty,adExecuteStream);
					

Back to the top

Steps to Run the Sample

1.Unzip the XPath.exe file.
2.Modify the connection string in XPathDlg.cpp to refer to a valid SQL Server 2000 database.
3.Compile and then run the application.

Back to the top

REFERENCES

For more information about XPATH query and XML, click the following article numbers to view the articles in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb//)
271780 (http://support.microsoft.com/kb/271780/EN-US/) SAMPLE: How To Retrieve XML Data using a SQL XML Query with ADO in Visual C++
271775 (http://support.microsoft.com/kb/271775/EN-US/) SAMPLE: How To Retrieve Relational Data Using OpenXML with ADO in Visual C++
272180 (http://support.microsoft.com/kb/272180/EN-US/) SAMPLE: How to Retrieve XML Data Using a Template File with ADO in Visual C++
%1 (http://support.microsoft.com/kb/%1/EN-US/) %2
SQL Server 2000 Books OnLine ADO 2.6 Documentation

Back to the top


APPLIES TO
Microsoft Data Access Components 2.6
Microsoft Data Access Components 2.7
Microsoft ActiveX Data Objects 2.6
Microsoft ActiveX Data Objects 2.7
Microsoft Visual C++ 6.0 Enterprise Edition
Microsoft Visual C++ 6.0 Professional Edition
Microsoft Visual C++, 32-bit Learning Edition 6.0
Microsoft SQL Server 2000 Standard Edition

Back to the top

Keywords: 
kbdownload kbcodesnippet kbfile kbinfo kbmsxmlnosweep KB271782

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.