<person>somebody</person>
#include "stdafx.h"
#include <stdio.h>
#import <msxml.dll>
int _tmain(int argc, _TCHAR* argv[]){
CoInitialize(0);//ATL库才能支持CComPtr. CComPtr<MSXML::IXMLDOMDocument> spDoc;
IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
IXMLDOMElementPtr pNode;
pDoc->createElement((_bstr_t)"person",&pNode);
pNode->put_text((_bstr_t)"somebody");
pDoc->appendChild(pNode,0);
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
printf("ok\n");
CoUninitialize();
return 0;
}
8 个解决方案
#1
CoUninitialize();前加上pDoc->Release()
#2
不行,我在CoUninitialize()前面加上pDoc->Release()或者pDoc.Release();都还是抱错误,提示是否把这个错误发送给微软。
我对程序作了小的调整。还是不行。
我对程序作了小的调整。还是不行。
#include "stdafx.h"
#include <stdio.h>
#import <msxml.dll> rename_namespace("msxml")
int _tmain(int argc, _TCHAR* argv[]){
CoInitialize(0);//ATL库才能支持CComPtr. CComPtr<MSXML::IXMLDOMDocument> spDoc;
msxml::IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
pDoc->put_async(VARIANT_FALSE);
pDoc->put_validateOnParse(VARIANT_FALSE);
pDoc->put_resolveExternals(VARIANT_FALSE);
msxml::IXMLDOMElementPtr pNode=pDoc->createElement((_bstr_t)"person");
pNode->put_text((_bstr_t)"somebody");
pDoc->appendChild(pNode);
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
pDoc->Release();
CoUninitialize();
return 0;
}
#3
把pDoc->put_async put_validateOnParse put_resolveExternals去掉。
#4
去掉了,还是不行。
谢谢
#5
//改成
IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
m_pDoc->loadXML((_bstr_t)(_T("<person></person>")))
m_pDoc->GetlastChild()->put_text((_bstr_t)"somebody");
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
printf("ok\n");
CoUninitialize();
IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
m_pDoc->loadXML((_bstr_t)(_T("<person></person>")))
m_pDoc->GetlastChild()->put_text((_bstr_t)"somebody");
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
printf("ok\n");
CoUninitialize();
#6
pNode.Release();
pDoc.Release();
pDoc.Release();
#7
我要的是新建一个文件,而不是改写一个已经存在的Node.
谢谢
#1
CoUninitialize();前加上pDoc->Release()
#2
不行,我在CoUninitialize()前面加上pDoc->Release()或者pDoc.Release();都还是抱错误,提示是否把这个错误发送给微软。
我对程序作了小的调整。还是不行。
我对程序作了小的调整。还是不行。
#include "stdafx.h"
#include <stdio.h>
#import <msxml.dll> rename_namespace("msxml")
int _tmain(int argc, _TCHAR* argv[]){
CoInitialize(0);//ATL库才能支持CComPtr. CComPtr<MSXML::IXMLDOMDocument> spDoc;
msxml::IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
pDoc->put_async(VARIANT_FALSE);
pDoc->put_validateOnParse(VARIANT_FALSE);
pDoc->put_resolveExternals(VARIANT_FALSE);
msxml::IXMLDOMElementPtr pNode=pDoc->createElement((_bstr_t)"person");
pNode->put_text((_bstr_t)"somebody");
pDoc->appendChild(pNode);
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
pDoc->Release();
CoUninitialize();
return 0;
}
#3
把pDoc->put_async put_validateOnParse put_resolveExternals去掉。
#4
去掉了,还是不行。
谢谢
#5
//改成
IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
m_pDoc->loadXML((_bstr_t)(_T("<person></person>")))
m_pDoc->GetlastChild()->put_text((_bstr_t)"somebody");
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
printf("ok\n");
CoUninitialize();
IXMLDOMDocumentPtr pDoc;
pDoc.CreateInstance(__uuidof(DOMDocument));
m_pDoc->loadXML((_bstr_t)(_T("<person></person>")))
m_pDoc->GetlastChild()->put_text((_bstr_t)"somebody");
pDoc->save((_variant_t)(_bstr_t)"d:\\my.xml");
printf("ok\n");
CoUninitialize();
#6
pNode.Release();
pDoc.Release();
pDoc.Release();
#7
我要的是新建一个文件,而不是改写一个已经存在的Node.
谢谢