C++ XML编程

1. How to use MSXML2 in C++?

First, we should import the "msxml6.tlb" file, the code as below:

  #import "..\Common\msxml6.tlb" raw_interfaces_only exclude("ISchemaElement", "ISchemaAttribute")

 

Then we can use the MSXML2 interfaces now, take for an example:

CoInitialize(NULL);

HRESULT hr = S_OK;

MSXML2::IXMLDOMDocument2Ptr spDoc = NULL;
hr = ::CoCreateInstance(__uuidof(MSXML2::DOMDocument60), 
                            NULL, 
                            CLSCTX_ALL,
                            __uuidof(MSXML2::IXMLDOMDocument2), 
                            (void**)&spDoc);
    if(FAILED(hr) || NULL == spDoc)
       return -1;

//....
sp->load(...);

sp->get_sirstChild(...);

sp->get_xml();

 

 2. How to use XmlLite in C++?

  MSDN Linker: http://msdn.microsoft.com/en-us/library/windows/desktop/ms752838(v=vs.85).aspx

HRESULT hr = S_OK;

   // Create reader.
   CComPtr<IXmlReader> spReader;
   hr = ::CreateXmlReader(__uuidof(IXmlReader),
                          reinterpret_cast<void**>(&spReader), 
                          0);
   if(FAILED(hr) || NULL == spReader)
      return;

   // Set input storage.
   CComPtr<IStream> spStream;
   hr = spReader->SetInput(spStream);
   if(FAILED(hr) || NULL == spStream)
      return;

   //spStream->Read

   // Enum node.
   XmlNodeType nodeType = XmlNodeType_None;
   while(S_OK == (hr = spReader->Read(&nodeType)))
   {
      UINT lineNum = 0;
      if(FAILED(spReader->GetLineNumber(&lineNum)))
         continue;
   }

   // Enum current node's attributes.
   for(hr = spReader->MoveToFirstAttribute();
       S_OK == hr;
       hr = spReader->MoveToNextAttribute())
   {
      LPCWSTR attValue;
      if(FAILED(spReader->GetValue(&attValue, NULL)))
         continue;
   }

 

 

 

 

转载于:https://www.cnblogs.com/nchxmoon/archive/2013/01/28/2880306.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值