msxml修改xml文本节点内容
<DATA>data文本信息<TIME>1988.01.30</TIME><VIS>1</VIS></DATA>如何通过MSXML修改“data文本信息”为“newInf...
<DATA>
data文本信息
<TIME>1988.01.30</TIME>
<VIS>1</VIS>
</DATA>
如何通过MSXML修改“data文本信息”为“newInfo”?谢谢! 展开
data文本信息
<TIME>1988.01.30</TIME>
<VIS>1</VIS>
</DATA>
如何通过MSXML修改“data文本信息”为“newInfo”?谢谢! 展开
1个回答
展开全部
#include <windows.h>
#include <msxml2.h>
#include <objbase.h>
#include <iostream>
#include <locale>
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")
#pragma comment(lib, "msxml2.lib")
LPCWSTR szXml =
L"<DATA>"
L" data文本信息"
L" <TIME>1988.01.30</TIME>"
L" <VIS>1</VIS>"
L"</DATA>";
int main()
{
static std::locale loc("");
std::locale::global(loc);
CoInitialize(NULL);
IXMLDOMDocument* pXml;
if (CoCreateInstance(CLSID_DOMDocument30, 0, CLSCTX_INPROC_SERVER, IID_IXMLDOMDocument, (LPVOID*)&pXml) == S_OK) {
VARIANT_BOOL vbSucc;
BSTR sXml = SysAllocString(szXml);
pXml->loadXML(sXml, &vbSucc);
SysFreeString(sXml);
if (vbSucc == VARIANT_TRUE) {
IXMLDOMNode* pNode;
if (pXml->get_firstChild(&pNode) == S_OK) {
IXMLDOMNode* pText;
if (pNode->get_firstChild(&pText) == S_OK) {
BSTR sText;
//pText->get_text(&sText);
//std::wcout << sText << std::endl;
//SysFreeString(sText);
sText = SysAllocString(L"newInfo");
pText->put_text(sText);
SysFreeString(sText);
pXml->get_xml(&sXml);
std::wcout << sXml << std::endl;
SysFreeString(sXml);
pText->Release();
} else {
std::cerr << "Can't get text node" << std::endl;
}
pNode->Release();
} else {
std::cerr << "Can't get child node" << std::endl;
}
} else {
std::cerr << "Can't load xml string" << std::endl;
}
pXml->Release();
} else {
std::cerr << "Can't create msxml object" << std::endl;
}
CoUninitialize();
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询