pugixml
pugixml比tinyxml快不止一个数量级
pugixml 可以在github上直接下载到源码 https://github.com/zeux/pugixml
包括两个头文件(pugixml.hpp pugiconfig.hpp) 和 一个源文件(pugixml.cpp)
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Profile FormatVersion="1">
<Tools>
<Tool Filename="jam" AllowIntercept="true">
<Description>Jamplus build system</Description>
</Tool>
<Tool Filename="mayabatch.exe" AllowRemote="true" OutputFileMasks="*.dae" DeriveCaptionFrom="lastparam" Timeout="40" />
<Tool Filename="meshbuilder_*.exe" AllowRemote="false" OutputFileMasks="*.mesh" DeriveCaptionFrom="lastparam" Timeout="10" />
<Tool Filename="texbuilder_*.exe" AllowRemote="true" OutputFileMasks="*.tex" DeriveCaptionFrom="lastparam" />
<Tool Filename="shaderbuilder_*.exe" AllowRemote="true" DeriveCaptionFrom="lastparam" />
</Tools>
</Profile>
----------------------------------------------------------------------------
pugi::xml_document doc;
if (!doc.load_file("xgconsole.xml")) return -1;
pugi::xml_node tools = doc.child("Profile").child("Tools");
for (pugi::xml_node tool = tools.first_child(); tool; tool = tool.next_sibling())
{
std::cout << "Tool:";
for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())
{
std::cout << " " << attr.name() << "=" << attr.value();
}
std::cout << std::endl;
}
<signals>
<signal>
<dtype>06</dtype>
<dtname>开关电源</dtname>
<id>0406016001</id>
<name>交流输入XX停电告警</name>
<value></value>
<result>不通过</result>
<desc>请检查通信接线,串口选择正确的协议库文件,并做告警测试</desc>
</signal>
<signal>
<dtype>06</dtype>
<dtname>开关电源</dtname>
<id>0406022001</id>
<name>防雷器故障告警</name>
<value></value>
<result>不通过</result>
<desc>请检查通信接线,串口选择正确的协议库文件,并做告警测试</desc>
</signal>
</signals>
pugi::xml_document doc;
if (!doc.load_file("/usr/local/dcd/html/Public/handtest.xml"))
{
std::cout << "load handtest.xml fail" << endl;
return;
}
pugi::xpath_node_set tools = doc.select_nodes("//signals/signal");
for (pugi::xpath_node_set::const_iterator it = tools.begin();it != tools.end(); ++it)
{
pugi::xpath_node node = *it;
string strdtype = node.node().child_value("dtype");
string strdtname = node.node().child_value("dtname");
string strID= node.node().child_value("id");
string strname = node.node().child_value("name");
string strvalue = node.node().child_value("value");
string strresult = node.node().child_value("result");
string strdesc = node.node().child_value("desc");
}