pugixml

pugixml比tinyxml快不止一个数量级
pugixml 可以在github上直接下载到源码 https://github.com/zeux/pugixml

包括两个头文件(pugixml.hpp  pugiconfig.hpp) 和 一个源文件(pugixml.cpp)

 

例子1

 1 <?xml version="1.0" encoding="UTF-8" standalone="no" ?>  
 2 <Profile FormatVersion="1">  
 3     <Tools>  
 4         <Tool Filename="jam" AllowIntercept="true">  
 5             <Description>Jamplus build system</Description>  
 6         </Tool>  
 7         <Tool Filename="mayabatch.exe" AllowRemote="true" OutputFileMasks="*.dae" DeriveCaptionFrom="lastparam" Timeout="40" />  
 8         <Tool Filename="meshbuilder_*.exe" AllowRemote="false" OutputFileMasks="*.mesh" DeriveCaptionFrom="lastparam" Timeout="10" />  
 9         <Tool Filename="texbuilder_*.exe" AllowRemote="true" OutputFileMasks="*.tex" DeriveCaptionFrom="lastparam" />  
10         <Tool Filename="shaderbuilder_*.exe" AllowRemote="true" DeriveCaptionFrom="lastparam" />  
11     </Tools>  
12 </Profile>
13 
14 pugi::xml_document doc;  
15 if (!doc.load_file("xgconsole.xml")) return -116 pugi::xml_node tools = doc.child("Profile").child("Tools");  
17 for (pugi::xml_node tool = tools.first_child(); tool; tool = tool.next_sibling())  
18 19  std::cout << "Tool:"20  for (pugi::xml_attribute attr = tool.first_attribute(); attr; attr = attr.next_attribute())  
21  {  
22   std::cout << " " << attr.name() << "=" << attr.value();  
23  }  
24  std::cout << std::endl;  
25
View Code

 

例子2

 1 <signals>
 2   <signal>
 3    <dtype>06</dtype>
 4    <dtname>开关电源</dtname>
 5     <id>0406016001</id>
 6     <name>交流输入XX停电告警</name>
 7     <value></value>
 8     <result>不通过</result>
 9     <desc>请检查通信接线,串口选择正确的协议库文件,并做告警测试</desc>
10   </signal>
11   <signal>
12    <dtype>06</dtype>
13    <dtname>开关电源</dtname>
14     <id>0406022001</id>
15     <name>防雷器故障告警</name>
16     <value></value>
17     <result>不通过</result>
18     <desc>请检查通信接线,串口选择正确的协议库文件,并做告警测试</desc>
19   </signal>
20 </signals>
21 
22 pugi::xml_document doc;
23     if (!doc.load_file("/usr/local/dcd/html/Public/handtest.xml"))
24     {
25         std::cout << "load handtest.xml fail" << endl;
26         return;
27     }
28     pugi::xpath_node_set tools = doc.select_nodes("//signals/signal");
29     for (pugi::xpath_node_set::const_iterator it = tools.begin();it != tools.end(); ++it)
30     {
31         pugi::xpath_node node = *it;
32         string strdtype = node.node().child_value("dtype");
33         string strdtname = node.node().child_value("dtname");
34         string strID= node.node().child_value("id");
35         string strname = node.node().child_value("name");
36         string strvalue = node.node().child_value("value");
37         string strresult = node.node().child_value("result");
38         string strdesc = node.node().child_value("desc");
39     }
View Code

 

posted @ 2018-06-21 16:36  osbreak  阅读(666)  评论(0编辑  收藏  举报