XML文件载入到_RecordsetPtr中怎么弄?

Windows100 2009-05-15 08:58:27
_RecordsetPtr->Save("TEST.XML")可以保存,可是载入貌似没有Load方法可以用哇

怎么办呢?
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
TianChong 2009-05-15
  • 打赏
  • 举报
回复
大家速度都这么快啊,哈哈,纯支持。
Windows100 2009-05-15
  • 打赏
  • 举报
回复
真是迅速。我测试下看看好不好用
biweilun 2009-05-15
  • 打赏
  • 举报
回复

#import "C:\Program files\Common Files\System\Ado\msado15.dll" rename_namespace("MSXML") rename("EOF", "ADOEOF")

#import "c:\winnt\system32\msxml.dll"
using namespace MSXML;

#include "stdio.h"
#include "io.h"
void dump_error(_com_error &e) ; //exception handling

void main()
{
HRESULT hr;
CoInitialize(NULL);

try
{
//open the connection, get the reocrdset ready
_ConnectionPtr pConn;
_RecordsetPtr pRs;

hr = pConn.CreateInstance(__uuidof(Connection));
hr = pRs.CreateInstance(__uuidof(Recordset));

pConn->CursorLocation = adUseClient;
_bstr_t strConn("Provider=sqloledb;Data Source=juliaj01;Initial Catalog=pubs;User Id=<username>;Password=<strong password>;");
hr = pConn->Open(strConn, "<username>", "<strong password>", adConnectUnspecified);
hr = pRs->Open("SELECT * from authors", pConn.GetInterfacePtr(), adOpenForwardOnly, adLockReadOnly, adCmdText);

//preparation to save RS as xml file,
struct _finddata_t xml_file;
long hFile;
if( (hFile = _findfirst("authors.xml", &xml_file )) != -1L)
{
DeleteFile("authors.xml"); //if the file exists, delete it
}

// 1. Persist it to an external xml file by calling Save with file name and adPersistXML
hr = pRs->Save("authors.xml", adPersistXML);

// 2. Persist it to ADO IStream Object
_StreamPtr pStream ; //declare one first
pStream.CreateInstance(__uuidof(Stream)); //create it after
hr = pRs->Save(pStream.GetInterfacePtr(), adPersistXML); //old trick, call Save

// 3. Persist it to DOM Document
IXMLDOMDocumentPtr pXMLDOMDoc;
pXMLDOMDoc.CreateInstance(__uuidof(DOMDocument));
hr = pRs->Save(pXMLDOMDoc.GetInterfacePtr(), adPersistXML);
// if you want to check out the content call printf(pXMLDOMDoc->Getxml());

//Recycle the Recordset object
hr = pRs->Close();

// 4. load the recordset back from the file by calling Open with MSPersist provider and adCmdFile.
// the Recordset will be a ReadOnly, Forwardly only
hr = pRs->Open("authors.xml","Provider=MSPersist;",adOpenForwardOnly,adLockReadOnly,adCmdFile);
hr = pRs->Close();

// 5. Load from IStream object, call Open, first param is pStream.GetInterfacePtr()

// Set the steam object position to the beginning of the stream:
pStream->Position = 0;

// call Open, passing in vtMissing for connection string, see Q245485 for details
hr = pRs->Open(pStream.GetInterfacePtr(),vtMissing, adOpenForwardOnly,adLockReadOnly,adCmdFile);

hr = pRs->Close();

// 6 .Load from DOM Document, call Open, first param is pXMLDOMDoc.GetInterfacePtr() and
// pass in vtMissing for connection string, see Q245485

hr = pRs->Open(pXMLDOMDoc.GetInterfacePtr(), vtMissing, adOpenForwardOnly, adLockReadOnly, adCmdFile);

hr = pRs->Close();



//Don't forget to clean up the stream object
hr = pStream->Close();

}
catch(_com_error &e)
{
dump_error(e);
}
}

void dump_error(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());

// Print Com errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);

}
biweilun 2009-05-15
  • 打赏
  • 举报
回复
给你找了个好资料http://support.microsoft.com/default.aspx?scid=kb;EN-US;262450
一看包你就会
biweilun 2009-05-15
  • 打赏
  • 举报
回复
LoadFromFile(szXMLPath)不就好了么

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧