91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.5MB
    文件類型: .rar
    金幣: 2
    下載: 0 次
    發布日期: 2023-11-07
  • 語言: C/C++
  • 標簽: XML??

資源簡介

c++讀取XML配置文件C++中并沒有操作XML文件的標準庫,因此大家需要使用各自熟悉的XML庫來解決XML文件的讀取與寫入。XML的一個重要用途是作為程序的配置文件,存儲程序運行相關的各種數據。本文總結了使用libxml2庫來對XML配置文件進行編程的一些經驗。最后提供了一個封裝好的類CXMLConfig,并詳細說明了該類的功能、使用方法和注意事項。

資源截圖

代碼片段和文件信息

#include?“stdafx.h“
#include?
#include?l/parser.h>
#include?l/xpath.h>
#include?

#include?“Code_Conv.h“

//代碼轉換:從一種編碼轉為另一種編碼???
int?code_convert(char*?from_charset?char*?to_charset?char*?inbuf
?int?inlen?char*?outbuf?int?outlen)
{
iconv_t?cd;
char**?pin?=?&inbuf;???
char**?pout?=?&outbuf;

cd?=?iconv_open(to_charsetfrom_charset);???
if(cd?==?0)
return?-1;
memset(outbuf0outlen);???
if(iconv(cd(const?char**)pin(unsigned?int?*)&inlenpout(unsigned?int*)&outlen)
==?-1)
return?-1;???
iconv_close(cd);
return?0;???
}

//UNICODE碼轉為GB2312碼???
//成功則返回一個動態分配的char*變量,需要在使用完畢后手動free,失敗返回NULL
char*?u2g(char?*inbuf)???
{
int?nOutLen?=?2?*?strlen(inbuf)?+?1;
char*?szOut?=?(char*)malloc(nOutLen);

if?(-1?==?code_convert(“utf-8““gb2312“inbufstrlen(inbuf)szOutnOutLen))
{
free(szOut);
szOut?=?NULL;
}
return?szOut;
}???

//GB2312碼轉為UNICODE碼???
//成功則返回一個動態分配的char*變量,需要在使用完畢后手動free,失敗返回NULL
char*?g2u(char?*inbuf)???
{
int?nOutLen?=?2?*?strlen(inbuf)?+?1;
char*?szOut?=?(char*)malloc(nOutLen);

if?(-1?==?code_convert(“gb2312““utf-8“inbufstrlen(inbuf)szOutnOutLen))
{
free(szOut);
szOut?=?NULL;
}
return?szOut;
}???

xmlXPathobjectPtr?get_nodeset(xmlDocPtr?doc?const?xmlChar?*xpath)?
{
xmlXPathContextPtr?context;
xmlXPathobjectPtr?result;

context?=?xmlXPathNewContext(doc);
if?(context?==?NULL)?
{
printf(“context?is?NULL\n“);
return?NULL;?
}

result?=?xmlXPathEvalexpression(xpath?context);
xmlXPathFreeContext(context);
if?(result?==?NULL)?
{
printf(“xmlXPathEvalexpression?return?NULL\n“);?
return?NULL;??
}

if?(xmlXPathNodeSetIsEmpty(result->nodesetval))?
{
xmlXPathFreeobject(result);
printf(“nodeset?is?empty\n“);
return?NULL;
}

return?result;
}

string?getxmlString(xmlDocPtr?doc?const?char?*szXpath)
{
xmlXPathobjectPtr?result;
string?strRel;

result?=?get_nodeset(docBAD_CAST?szXpath);

if?(result?==?NULL)?
{
printf(“xmlXPathEvalexpression?return?NULL\n“);?
return?NULL;??
}

xmlNodeSetPtr?nodeSetPtr?=?result->nodesetval;

//查出符合xpath的節點集合
if?(xmlXPathNodeSetIsEmpty(nodeSetPtr))?
{
xmlXPathFreeobject(result);
printf(“nodeset?is?empty\n“);
return?NULL;
}

//查出節點集合中唯一節點的內容值
xmlNodePtr?nodePtr?=?nodeSetPtr->nodeTab[0];????
strRel?=?(const?char*)xmlNodeGetContent(nodePtr);
return?strRel;
}

int?getxmlInt(xmlDocPtr?doc?const?char*?szXpath)
{
xmlXPathobjectPtr?result;
int?iRel;

result?=?get_nodeset(docBAD_CAST?szXpath);

if?(result?==?NULL)?
{
printf(“xmlXPathEvalexpression?return?NULL\n“);?
return?NULL;??
}

xmlNodeSetPtr?nodeSetPtr?=?result->nodesetval;

//查出符合xpath的節點集合
if?(xmlXPathNodeSetIsEmpty(nodeSetPtr))?
{
xmlXPathFreeobject(result);
printf(“nodeset?is?empty\n“);
return?NULL;
}

xmlNodePtr?nodePtr?=?nodeSetPtr->nodeTab[0];????
iRel?=?atoi((const?cha

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????4056??2008-05-27?09:44??xmlConfigFile\Code_Conv.cpp

?????文件????????930??2008-05-27?09:44??xmlConfigFile\Code_Conv.h

?????文件?????????62??2008-05-26?14:59??xmlConfigFile\Debug\Helloxml.xml

?????文件?????888832??2006-05-03?21:57??xmlConfigFile\Debug\iconv.dll

?????文件?????967168??2007-08-27?20:11??xmlConfigFile\Debug\libxml2.dll

?????文件????????162??2008-05-27?15:03??xmlConfigFile\Debug\XPathConfig.xml

?????文件????????162??2008-05-27?15:03??xmlConfigFile\Debug\XPathConfig_bak.xml

?????文件??????55808??2007-07-02?17:06??xmlConfigFile\Debug\zlib1.dll

?????文件??????14149??2008-05-27?16:20??xmlConfigFile\Helloxml\Debug\Helloxml.obj

?????文件?????214152??2008-05-26?15:48??xmlConfigFile\Helloxml\Debug\Helloxml.pch

?????文件?????508928??2008-05-27?16:20??xmlConfigFile\Helloxml\Debug\Helloxml.pdb

?????文件???????2508??2008-05-26?15:48??xmlConfigFile\Helloxml\Debug\StdAfx.obj

?????文件??????66560??2008-05-27?16:20??xmlConfigFile\Helloxml\Debug\vc60.idb

?????文件?????110592??2008-05-27?16:20??xmlConfigFile\Helloxml\Debug\vc60.pdb

?????文件???????1146??2008-05-27?15:32??xmlConfigFile\Helloxml\Helloxml.cpp

?????文件???????4639??2008-05-26?15:50??xmlConfigFile\Helloxml\Helloxml.dsp

?????文件???????1379??2008-05-27?16:20??xmlConfigFile\Helloxml\Helloxml.plg

?????文件???????1220??2008-05-26?15:48??xmlConfigFile\Helloxml\ReadMe.txt

?????文件????????295??2008-05-26?15:48??xmlConfigFile\Helloxml\StdAfx.cpp

?????文件????????769??2008-05-26?15:48??xmlConfigFile\Helloxml\StdAfx.h

?????文件???????2508??2008-05-27?10:42??xmlConfigFile\UseClass\Debug\StdAfx.obj

?????文件??????44244??2008-05-27?14:30??xmlConfigFile\UseClass\Debug\UseClass.obj

?????文件?????214152??2008-05-27?10:42??xmlConfigFile\UseClass\Debug\UseClass.pch

?????文件?????582656??2008-05-27?14:31??xmlConfigFile\UseClass\Debug\UseClass.pdb

?????文件?????123904??2008-05-27?14:31??xmlConfigFile\UseClass\Debug\vc60.idb

?????文件?????176128??2008-05-27?14:31??xmlConfigFile\UseClass\Debug\vc60.pdb

?????文件??????67456??2008-05-27?14:31??xmlConfigFile\UseClass\Debug\xmlConfig.obj

?????文件???????1220??2008-05-27?10:37??xmlConfigFile\UseClass\ReadMe.txt

?????文件????????295??2008-05-27?10:37??xmlConfigFile\UseClass\StdAfx.cpp

?????文件????????769??2008-05-27?10:37??xmlConfigFile\UseClass\StdAfx.h

............此處省略33個文件信息

評論

共有 條評論