Edit

Share via


CXMLAccessor Class

Allows you to access data sources as string data when you have no knowledge of the data store's schema (underlying structure).

Syntax

class CXMLAccessor : public CDynamicStringAccessorW

Requirements

Header: atldbcli.h

Members

Methods

Name Description
GetXMLColumnData Retrieves the column information.
GetXMLRowData Retrieves the entire contents of a table by rows.

Remarks

However, CXMLAccessor differs from CDynamicStringAccessorW in that it converts all data accessed from the data store as XML-formatted (tagged) data. This is especially useful for output to XML-aware Web pages. The XML tag names will match the data store's column names as closely as possible.

Use CDynamicAccessor methods to obtain column information. You use this column information to create an accessor dynamically at run time.

The column information is stored in a buffer created and managed by this class. Obtain column information using GetXMLColumnData or obtain column data by rows using GetXMLRowData.

Example

void DoCXMLAccessorTest()
{
   HRESULT hr = CoInitialize(NULL);

   CDataSource ds;
   CSession ss;

   CTable<CXMLAccessor> rs;

   // The following is an example initialization string:
   hr = ds.OpenFromInitializationString(L"Provider=Microsoft.Jet.OLEDB.4.0;"
      L"User ID=Admin;Data Source=Snippet.mdb;Mode=Share Deny None;"
      L"Extended Properties=\"\";Jet OLEDB:System database=\"\";"
      L"Jet OLEDB:Registry Path=\"\";Jet OLEDB:Database Password=\"\";"
      L"Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;"
      L"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;"
      L"Jet OLEDB:New Database Password=\"\";Jet OLEDB:Create System Database=False;"
      L"Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;"
      L"Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False");

   hr = ss.Open(ds);
   hr = rs.Open(ss, L"Customer"); // Customer is a table name in the database.

   CStringW strColumnInfo;
   rs.GetXMLColumnData(strColumnInfo);
   wprintf_s(L"%s\n", strColumnInfo);

   hr = rs.MoveFirst();
   while(SUCCEEDED(hr) && hr != DB_S_ENDOFROWSET)
   {
      CStringW strRowData;
      rs.GetXMLRowData(strRowData);
      wprintf_s(L"%s\n", strRowData);
      hr = rs.MoveNext();
   }

   ss.Close();
   ds.Close();
   CoUninitialize();
}

CXMLAccessor::GetXMLColumnData

Retrieves the column type information of a table as XML-formatted string data, by column.

Syntax

HRESULT GetXMLColumnData(CSimpleStringW& strOutput) throw();

Parameters

strOutput
[out] A reference to a string buffer containing the column type information to be retrieved. The string is formatted with XML tag names that match the data store's column names.

Return Value

One of the standard HRESULT values.

Remarks

The following shows how the column type information is formatted in XML. type specifies the column's data type. Note that the data types are based on OLE DB data types, not those of the database being accessed.

<columninfo>

<column type = I2/> ColumnName

</columninfo>

CXMLAccessor::GetXMLRowData

Retrieves the entire contents of a table as XML-formatted string data, by row.

Syntax

HRESULT GetXMLRowData(CSimpleStringW& strOutput,
   bool bAppend = false) throw();

Parameters

strOutput
[out] A reference to a buffer containing the table data to be retrieved. The data is formatted as string data with XML tag names that match the data store's column names.

bAppend
[in] A Boolean value specifying whether to append a string to the end of the output data.

Return Value

One of the standard HRESULT values.

Remarks

The following shows how the row data is formatted in XML. DATA below represents the row data. Use move methods to move to the desired row.

<row>

<column name>DATA</column name>

</row>

See also

OLE DB Consumer Templates
OLE DB Consumer Templates Reference
CAccessor Class
CDynamicAccessor Class
CDynamicParameterAccessor Class
CDynamicStringAccessor Class
CDynamicStringAccessorA Class
CDynamicStringAccessorW Class
CManualAccessor Class