基于ATL使用MSXML2生成XML文件
2010-11-10 19:37
471 查看
#include <atlbase.h> #include <MsXml2.h> #include <atlconv.h> void main(int argc,char*argv[]) { CoInitialize(NULL); CComPtr<IXMLDOMDocument> spDoc; spDoc.CoCreateInstance(__uuidof(DOMDocument)); CComPtr<IXMLDOMElement> spRootElement; spDoc->createElement(L"China",&spRootElement); LPWSTR lpwAttri = L"+86"; USES_CONVERSION; CComVariant varAttri = T2OLE(lpwAttri); spRootElement->setAttribute(L"id",varAttri); CComPtr<IXMLDOMNode> spChildNode; spDoc->appendChild(spRootElement,&spChildNode); if(spChildNode) spChildNode.Release(); CComPtr<IXMLDOMElement> spChildElement; spDoc->createElement(L"BeiJing",&spChildElement); spRootElement->appendChild(spChildElement,&spChildNode); spChildNode->put_text(L"010"); if(spChildElement) spChildElement.Release(); if(spChildNode) spChildNode.Release(); spDoc->createElement(L"ShangHai",&spChildElement); spRootElement->appendChild(spChildElement,&spChildNode); spChildNode->put_text(L"020"); CComVariant varFile = L"D://test.xml"; spDoc->save(varFile); spChildElement.Release(); spChildNode.Release(); spRootElement.Release(); spDoc.Release(); CoUninitialize(); }
生成的XML:
- <China id="+86"> <BeiJing>010</BeiJing> <ShangHai>020</ShangHai> </China>
相关文章推荐
- 使用MSXML2生成XML文件
- 基于xml文件生成array文件(使用与seo)
- 使用MsXml2 生成xml文件
- java使用freemarker生成静态html页面,基于中文API(简单版)
- 使用xsd.exe命令 根据指定的xml文件生成对应的xsd架构文件
- 使用Pull解析器读取XML文件和生成XML文件
- 使用Dom4j生成xml文件
- 使用Pull解析器读取XML文件和生成XML文件
- 基于ATL的控件中使用加速键(AtlLoadAccelerators)
- 使用idea根据数据库表生成java model类,基于hibernate
- 使用MSXML2生成XML文件
- 这是我学习COM遇到的几个基本问题其解决 黄森堂(vcmfc)著 1.我用ATL生成一个组件对象,我在COM中使用IDD_IEncrypt,这个在哪里写义,是啥?GUID? 答:IDD_IEncry
- android学习——使用SAX、DOM 和 PULL 解析xml文件,及使用pull生成xml文件
- 基于ONVIF协议的(IPC)客户端程序开发-3:使用gSOAP生成Web Services框架代码
- .NET Core使用skiasharp文字头像生成方案(基于docker发布)
- Python中使用dom模块生成XML文件示例
- Android中使用Pull解析器生成XML文件和读取xml文件
- 基于ONVIF协议的(IPC)客户端程序开发-5:使用gSOAP生成ONVIF框架代码
- PHP使用JPG生成GIF动画图片,基于php_imagick_st-Q8.dll
- 基于微信公众平台的二维码签到系统-----(2)二维码的生成以及内网穿透ngrok代理服务器的使用