-
February 27th, 2004, 05:27 AM
#1
How to Save Xml Dom to IStream ?(with anwser in it)
keyword: IStream Dom Save encoding
when you create a MS DOM object,you maybe want to save the content to memory ,not to file ,How to do this?i have found all the world, no answer.so i write it .
you can do it like this,
... ...
int nSize=0;
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, nSize);
IStream* pStream = NULL;
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
hr=pXMLDom->save(_variant_t(pStream));
if (pStream==NULL) return 0;
LARGE_INTEGER liBeggining = { 0 };
pStream->Seek(liBeggining, STREAM_SEEK_SET, NULL);
DWORD wTemp=GlobalSize(hGlobal);
LPBYTE lpData = (LPBYTE)GlobalLock(hGlobal); //you can use lpData doing your needs.
pStream->Release();
remarks:
Why do that ?when you create XML with DOM ,then not save to file,maybe save it to Database,but ,when you want to get xml content like thisXMLDom->get_xml(&bstr),you can not get the encoding part,maybe you don't understand what i'm saying,look:
you maybe create xml use dom like this:
bstr = SysAllocString(L"xml");
bstr1 = SysAllocString(L"version='1.0' encoding='GBK'");
HRCALL(pXMLDom->createProcessingInstruction(
bstr,bstr1, &pi),
"createProcessingInstruction:");
//AppendChildToParent(pi, pXMLDom);
vNullVal.vt = VT_NULL;
pXMLDom->insertBefore(pi, vNullVal,&pBuf);
if you use pXMLDom->get_xml(&bstr),you can get :
<?xml version="1.0" ?>
you can not get encoding='GBK'
if you use IStream as i say just now,you can get :
<?xml version="1.0" encoding="GBK"?>
,of course,if you save to file,no this problem.
if this help you,please reply to let me know.
Last edited by xqyz8888; February 27th, 2004 at 05:39 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|