CXMLAccessor Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at 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  

Members

Methods

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();
}

Requirements

Header: atldbcli.h

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