There are two separate methods of retrieving XML data from a data source: one uses
Functionality | CStreamRowset | CXMLAccessor |
---|---|---|
Amount of data transferred |
Retrieves data from all columns and rows at once. |
Retrieves data from all columns but only one row at a time. You must navigate rows using methods such as MoveNext. |
Formatting the string |
SQLВ Server formats the XML string and sends it to the consumer. |
Retrieves rowset data in its native format (requests that the provider send it as Unicode strings) and then builds the string containing the data in XML format. |
Control over formatting |
You have some level of control over how the XML string is formatted by setting some SQLВ Server 2000-specific properties. |
You have no control over the format of the generated XML string. |
While CStreamRowset provides a more overall efficient way of retrieving data in XML format, it is only supported by SQLВ Server 2000.
Retrieving XML Data Using CStreamRowset
You specify
В | Copy Code |
---|---|
CCommand< CAccessor<CMyAccessor>, CStreamRowset > myCmd; |
-or-
В | Copy Code |
---|---|
CCommand< CNoAccessor, CStreamRowset > myCmd; |
Normally when you call CCommand::Open (specifying, for example, CRowset as the TRowset class), it obtains an IRowset pointer. ICommand::Execute returns an IRowset pointer, which is stored in the m_spRowset member of the CRowset object. Methods such as MoveFirst, MoveNext, and GetData use that pointer to retrieve the data.
By contrast, when you call CCommand::Open (but specify CStreamRowset as the TRowset class), ICommand::Execute returns an
В | Copy Code |
---|---|
myCmd.m_spStream->Read() |
SQLВ Server 2000 performs the XML formatting and returns all columns and all rows of the rowset as one XML string.
For an example using the Read method, see "Adding XML Support to the Consumer" in Implementing a Simple Consumer.
Note |
---|
XML support using CStreamRowset works with SQLВ Server 2000 only and requires that you have the OLE DB Provider for SQLВ Server 2000 (installed with MDAC). |
Retrieving XML Data Using CXMLAccessor
Use CXMLAccessor as you would any other accessor class, passing it as a template parameter to CCommand or CTable:
В | Copy Code |
---|---|
CTable<CXMLAccessor, CRowset> rs; |
Use
В | Copy Code |
---|---|
// Open data source, session, and rowset hr = rs.MoveFirst(); while( SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET ) { CStringW strRowData; myCmd.GetXMLRowData(strRowData); printf_s( "%S\n", strRowData ); hr = rs.MoveNext(); } |
You can use