msxml4.dll中的那个函数可以产生跟节点,我要在程序中生成xml文件

bluecrest 2002-07-03 02:08:44
?
...全文
25 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zee 2002-07-03
  • 打赏
  • 举报
回复
为什么要先getdocumentElement呢?
而且pItemElement在create之后没有Append到Doc上啊。
这样试试:

m_pDoc.CreateInstance("Msxml2.DOMDocument.4.0");


// removed m_pDoc->get_documentElement(&pRoot);

pItemElement=m_pDoc->createElement("RECORD");
//Add :
m_pDoc->appendChild(pItemElement);
bsName=CString("MOBILE").AllocSysString();
varValue=_bstr_t("fdasfdasfds");
pChildElement=m_pDoc->createElement(bsName);
pChildElement->put_text(varValue);
pItemElement->appendChild(pChildElement);

bsName=CString("CONTENT").AllocSysString();
varValue=_bstr_t("fkjkfjf");
pChildElement=m_pDoc->createElement(bsName);
pChildElement->put_text(varValue);
pItemElement->appendChild(pChildElement);




m_pDoc->save(_variant_t(path));
bluecrest 2002-07-03
  • 打赏
  • 举报
回复
代码如下

m_pDoc.CreateInstance("Msxml2.DOMDocument.4.0");


m_pDoc->get_documentElement(&pRoot);

pItemElement=m_pDoc->createElement("RECORD");

bsName=CString("MOBILE").AllocSysString();
varValue=_bstr_t("fdasfdasfds");
pChildElement=m_pDoc->createElement(bsName);
pChildElement->put_text(varValue);
pItemElement->appendChild(pChildElement);

bsName=CString("CONTENT").AllocSysString();
varValue=_bstr_t("fkjkfjf");
pChildElement=m_pDoc->createElement(bsName);
pChildElement->put_text(varValue);
pItemElement->appendChild(pChildElement);




m_pDoc->save(_variant_t(path));


出错如下
文档缺少一个顶层元素
bluecrest 2002-07-03
  • 打赏
  • 举报
回复
那如何产生document呢
没有这个对象我是不能createnode的
Zee 2002-07-03
  • 打赏
  • 举报
回复
CreateNode即可。
根节点和子节点在创建上没有什么不同

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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