记录阿里巴巴QA架构组成长点滴。2008年关键词为效率,技术,影响力!QA/测试架构师定义:开发和设计测试框架测试库;纵横全局的考虑产品的功能,设计复杂的测试系统;负责研发某一项特定的测试技术;为公司考虑如何提高测试效率。领导公司测试技术的发展和测试策略上的方向,关注整个公司的测试部门的问题,前瞻性的考虑未来的版本的测试策略和技术。测试架构师计划/设计测试平台,关注着产品的测试过程,提供咨询服务,影响到公司内的测试机构测试社区,以及开发机构等,对产品各个方面施加深远而正确的影响,最终提高整体软件质量。

MSXML6 SDK解析中文XML文件

上一篇 / 下一篇  2008-08-10 01:54:08 / 个人分类:性能测试与容量规划

1.1      下载msxml6_SDK.msi安装

 

http://www.microsoft.com/downloads/details.aspx?familyid=993C0BCF-3BCF-4009-BE21-27E85E1857B1&displaylang=en

 

默认安装在C:\Program Files\MSXML 6.0\

 

1.2      vc6上建立编译环境

Preprocessor编译加入Additional include directorie加入C:\Program Files\MSXML 6.0\inc

 

LINK module加入: msxml6.lib

 

Link Additional library path加入:C:\Program Files\MSXML 6.0\lib

1.3      解决vc6 link错误问题

 

msxml6.lib(msxml6_i.obj) : fatal error LNK1103: debugging information corrupt; recompile module

 

参见

http://www.armleg.com/forum/viewtopic.php?p=388&sid=414fd259dcf02a90f150708296924178&mforum=diodiaforum

 

All I get from Google is that VS6 doesn't work with platform SDK's later than february 2003.

 

必须采用release版本编译、链接才成功。(build->set active project configuration->win32 release)

 

 

1.4      汉语问题

 

      //解决汉语问题

      setlocale(LC_ALL,"chinese-simplified");

 

1.5      源代码

 

#include <objbase.h>

#include <msxml6.h>

#include <stdio.h>

#include <windows.h>

#include <stdarg.h>

#include <locale.h>

#include <AtlBase.h>

 

#import <msxml6.dll> raw_interfaces_only

 

// Macro that calls a COM method returning HRESULT value:

#define HRCALL(a, errmsg) \

do { \

   hr = (a); \

   if (FAILED(hr)) { \

       dprintf( "%s:%d HRCALL Failed: %s\n 0x%.8x = %s\n", \

               __FILE__, __LINE__, errmsg, hr, #a ); \

       goto clean; \

   } \

} while (0)

 

// Helper function that put output in stdout and debug window

// in Visual Studio:

void dprintf( char * format, ...)

{

   static char buf[1024];

   va_list args;

   va_start( args, format );

      sprintf(buf, format, args);

   vsprintf(buf, format, args );

   va_end( args);

   OutputDebugStringA( buf);

   printf("%s", buf);

}

 

// Helper function to create a DOM instance:

IXMLDOMDocument3 * DomFromCOM()

{

  HRESULT hr;

  IXMLDOMDocument3 *pxmldoc = NULL;

 

  HRCALL( CoCreateInstance(CLSID_DOMDocument60,

                 NULL,

                 CLSCTX_INPROC_SERVER,

                 //__uuidof(IXMLDOMDocument),

                            IID_IXMLDOMDocument3,

                 (void**)&pxmldoc),

                 "Create a new DOMDocument");

 

   HRCALL( pxmldoc->put_async(VARIANT_FALSE),

           "should never fail");

   HRCALL( pxmldoc->put_validateOnParse(VARIANT_FALSE),

           "should never fail");

   HRCALL( pxmldoc->put_resolveExternals(VARIANT_FALSE),

           "should never fail");

 

   return pxmldoc;

clean:

   if (pxmldoc)

   {

       pxmldoc->Release();

   }

   return NULL;

}

 

int Get_nodeValue(IXMLDOMElement * pRoot , char * tagName,char *ret_text)

{

      USES_CONVERSION;

   IXMLDOMNodeList * pNodeList = NULL;

      IXMLDOMNode * pNode = NULL;

      HRESULT hr;

      BSTR bstr = NULL;

 

      hr=pRoot->getElementsByTagName(_bstr_t(tagName),&pNodeList) ;

      if (FAILED(hr))

             return -1;

 

      //取第一个满足条件的

      hr= pNodeList->get_item(0,&pNode);

      if (FAILED(hr))

             return -1;

      

      hr=pNode->get_text(&bstr);

      if (FAILED(hr))

             return -1;

      //dprintf("v=%s\n",W2A(bstr));

      sprintf(ret_text,W2A(bstr));

      return 0;

}

 

int main(int argc, char* argv[])

{

 /*

 HRESULT hr;

 IXMLDOMDocument3 *pXMLDoc = NULL;

 CoInitialize(NULL);

 hr = CoCreateInstance(CLSID_DOMDocument60,

                    NULL,

                    CLSCTX_INPROC_SERVER,

                    IID_IXMLDOMDocument3,

                    (void**)&pXMLDoc);

  if (FAILED(hr))

  {

     printf("Error code: %x\n", hr);

  }

*/

      USES_CONVERSION;

   IXMLDOMDocument3 *pXMLDom=NULL;

   IXMLDOMParseError *pXMLErr=NULL;

   BSTR bstr = NULL;

   VARIANT_BOOL status;

   VARIANT var;

   HRESULT hr;

      IXMLDOMElement * pRoot = NULL;

      VARIANT_BOOL isHasChild=VARIANT_FALSE;

      long listLen=0;

      long i=0;

      char ret_scrīpttext[48]={0};

      char ret_steptime[48]={0};

      char sz_xmlFile[]="lr.xml";

      

   CoInitialize(NULL);

      //解决汉语编码问题

      setlocale(LC_ALL,"chinese-simplified");

 

   pXMLDom = DomFromCOM();

   if (!pXMLDom) 

             goto clean;

      

   VariantInit(&var);

   V_BSTR(&var) = SysAllocString(_bstr_t(sz_xmlFile));

   V_VT(&var) = VT_BSTR;

   HRCALL(pXMLDom->load(var, &status), "");

 

   if (status!=VARIANT_TRUE) {

       HRCALL(pXMLDom->get_parseError(&pXMLErr),"");

       HRCALL(pXMLErr->get_reason(&bstr),"");

       dprintf("Failed to load DOM from stocks.xml. %S\n",

                   bstr);

       goto clean;

      

 

   }

   HRCALL(pXMLDom->get_xml(&bstr), "");

 

   dprintf("XML DOM loaded from stocks.xml:\n%S\n",bstr);

 

      HRCALL( pXMLDom->get_documentElement(&pRoot) ,"get_documentElement");

  

      Get_nodeValue(pRoot,"scrīpt",ret_scrīpttext);

      Get_nodeValue(pRoot,"steptime",ret_steptime);

      

      printf("%s %d",ret_scrīpttext,atoi(ret_steptime));

 /*

   HRCALL(pNode->get_nodeValue(&value),"get_nodeValue");

      USES_CONVERSION;  

   dprintf("v=%s\n",OLE2A(value.bstrVal));

      SysFreeString(bstr);

*/

 

clean:

   if (bstr) SysFreeString(bstr);

   if (&var) VariantClear(&var);

   if (pXMLErr) pXMLErr->Release();

   if (pXMLDom) pXMLDom->Release();

 

   CoUninitialize();

   return 0;

}

 

Lr.Xml文件如下(notepad保存为ascii格式)

<?xml version="1.0" encoding="GB2312"?>

 

<root>

   <scrīpt type="string">d:\工程\1.lrr</scrīpt>

   <steptime>30</steptime>

</root>


TAG: MSXML setlocale 汉字 xml get_documentElement SysAllocString BSTR 性能测试与容量规划

 

评分:0

我来说两句

日历

« 2022-01-13  
      1
2345678
9101112131415
16171819202122
23242526272829
3031     

数据统计

  • 访问量: 114852
  • 日志数: 163
  • 文件数: 1
  • 建立时间: 2008-02-26
  • 更新时间: 2008-12-10

RSS订阅

Open Toolbar