我想要一个用vs2010写一个能生成xml文件的代码,简单一点的,求帮助! 5

我有更好的答案

1条回答


 oleaut32.lib"
       IXMLDOMElement* eBaidu.h>
#include <msxml2;comment(lib;      ,    
  
#pragma comment(lib, "ole32.lib" "BSTR S_OK) {
 , 
   )
 
int  ==   S_OK) {
     SysFreeString(eBaiduName);     main()
{
    if (CoInitialize(NULL) ==  pXmlDoc)  );SysFreeString(eZhidaoName);
            eBaidu->  
       eBaidu);pXmlDoc->NULL);  put_async(0xffff);     
    ,   )
#pragma   
 IXMLDOMDocument* = SysAllocString(L"Baidu"   putref_documentElement(eBaidu);
             
            IXMLDOMElement*  " 
    )
#pragma            if   msxml2.lib"eBaiduName (CoCreateInstance(CLSID_DOMDocument30;  pXmlDoc; pXmlDoc-> 
 , IID_IXMLDOMDocument;  pXmlDoc-> (LPVOID*)&appendChild(eZhidao;  , eZhidao; ); createElement(eZhidaoName; ,       , eZhidaoName =  
            
            IXMLDOMElement* eCPP;
            BSTR eCPPName = SysAllocString(L"CPP");
            pXmlDoc->createElement(eCPPName, &eCPP);
            SysFreeString(eCPPName);
            BSTR eCPPText = SysAllocString(L"C/C++ Questions");
            eCPP->put_text(eCPPText);
            SysFreeString(eCPPText);
            eZhidao->appendChild(eCPP, NULL);
 
            IXMLDOMElement* eJava;
            BSTR eJavaName = SysAllocString(L"Java");
            pXmlDoc->createElement(eJavaName, &eJava);
            SysFreeString(eJavaName);
            BSTR eJavaText = SysAllocString(L"Java Questions");
            eJava->put_text(eJavaText);
            SysFreeString(eJavaText);
            eZhidao->appendChild(eJava, NULL);
             
            IXMLDOMElement* eBaike;
            BSTR eBaikeName = SysAllocString(L"Baike");
            pXmlDoc->createElement(eBaikeName, &eBaike);
            SysFreeString(eBaikeName);
            eBaidu->appendChild(eBaike, NULL);
             
            eZhidao->Release();
            eBaike->Release();
 
            BSTR szXml;
            pXmlDoc->get_xml(&szXml);
            pXmlDoc->Release();
             
            eBaidu->Release();
             
            wprintf(L"%s", szXml);
            SysFreeString(szXml);
        } else {
            fprintf(stderr, "%s", "Can't create msxml instance");
        }
 
        CoUninitialize();
    }
 
    return 0;
}

调用系统里带的微软的那个xml库(com组件)生成xml的例子

会比较麻烦一点,不过好处是不需要单独安装额外的库啊什么的

;   NULL, CLSCTX_INPROC_SERVER; Zhidao"    
#include <objbase.h>
     .h>
#include <stdio.h><    createElement(eBaiduName, & SysAllocString(L" pXmlDoc->   
     BSTR  
#include  &eZhidao);    comment(lib;oleauto
空雪梦见 | 发布于2013-12-06
评论

为您推荐:

×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消