欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
RapidXml使用方法
一、寫(xiě)xml 文件
[cpp] view plaincopy
#include <iostream>
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_print.hpp"
using namespace rapidxml;
int main()
{
xml_document<> doc;
xml_node<>* rot = doc.allocate_node(rapidxml::node_pi,doc.allocate_string("xml version='1.0' encoding='utf-8'"));
doc.append_node(rot);
xml_node<>* node =   doc.allocate_node(node_element,"config","information");
xml_node<>* color =   doc.allocate_node(node_element,"color",NULL);
doc.append_node(node);
node->append_node(color);
color->append_node(doc.allocate_node(node_element,"red","0.1"));
color->append_node(doc.allocate_node(node_element,"green","0.1"));
color->append_node(doc.allocate_node(node_element,"blue","0.1"));
color->append_node(doc.allocate_node(node_element,"alpha","1.0"));
xml_node<>* size =   doc.allocate_node(node_element,"size",NULL);
size->append_node(doc.allocate_node(node_element,"x","640"));
size->append_node(doc.allocate_node(node_element,"y","480"));
node->append_node(size);
xml_node<>* mode = doc.allocate_node(rapidxml::node_element,"mode","screen mode");
mode->append_attribute(doc.allocate_attribute("fullscreen","false"));
node->append_node(mode);
std::string text;
rapidxml::print(std::back_inserter(text), doc, 0);
std::cout<<text<<std::endl;
std::ofstream out("config.xml");
out << doc;
system("PAUSE");
return EXIT_SUCCESS;
}
生成的xml如下
[html] view plaincopy
<?xml version="1.0" encoding="utf-8" ?>
- <config>
- <color>
<red>0.1</red>
<green>0.1</green>
<blue>0.1</blue>
<alpha>1.0</alpha>
</color>
- <size>
<x>640</x>
<y>480</y>
</size>
<mode fullscreen="false">screen mode</mode>
</config>
寫(xiě)文件例子2:
[cpp] view plaincopy
#include <string>
#include <iostream>
#include <fstream>
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_print.hpp"
using namespace rapidxml;
using namespace std;
int main(int argc, char* argv[])
{
xml_document<> doc; //是解析器
char a[] = "<top>"http://如果單獨傳, 就不能加上x(chóng)ml的頭部信息,
//否則會(huì )報錯
"<name>tangqiang</name>"
"<age>22</age>"
"</top>";
char* p = a;
doc.parse<0>(p);
xml_node<>* node = doc.first_node();//去頂級結點(diǎn)
cout << (node->name())<< endl;
node = node->first_node();
while (node) {
cout << node->name() << node->value() << endl;//name() value()返回的字符串不會(huì )去掉首尾的空白字符
node = node->next_sibling();
}
ofstream out("test.xml");//ofstream 默認時(shí),如果文件存在則會(huì )覆蓋原來(lái)的內容,不存在則會(huì )新建
out << doc;//doc 這樣輸出時(shí)在目標文件中不會(huì )有xml 頭信息---<?xml version='1.0' encoding='utf-8' >
out.close();
system("pause");
return 0;
}
生成的xml如下
[html] view plaincopy
<top>
<name>tangqiang</name>
<age>22</age>
</top>
二、讀取xml文件
[cpp] view plaincopy
#include <iostream>
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_print.hpp"
using namespace rapidxml;
int main()
{
file<> fdoc("config.xml");
std::cout<<fdoc.data()<<std::endl;
xml_document<>   doc;
doc.parse<0>(fdoc.data());
std::cout<<doc.name()<<std::endl;
//! 獲取根節點(diǎn)
xml_node<>* root = doc.first_node();
std::cout<<root->name()<<std::endl;
//! 獲取根節點(diǎn)第一個(gè)節點(diǎn)
xml_node<>* node1 = root->first_node();
std::cout<<node1->name()<<std::endl;
xml_node<>* node11 = node1->first_node();
std::cout<<node11->name()<<std::endl;
std::cout<<node11->value()<<std::endl;
//! 添加之后再次保存
//需要說(shuō)明的是rapidxml明顯有一個(gè)bug
//那就是append_node(doc.allocate_node(node_element,"h","0"));的時(shí)候并不考慮該對象是否存在!
xml_node<>* size = root->first_node("size");
size->append_node(doc.allocate_node(node_element,"w","0"));
size->append_node(doc.allocate_node(node_element,"h","0"));
std::string text;
rapidxml::print(std::back_inserter(text),doc,0);
std::cout<<text<<std::endl;
std::ofstream out("config.xml");
out << doc;
system("PAUSE");
return EXIT_SUCCESS;
}
生成的xml為
[html] view plaincopy
<config>
<color>
<red>0.1</red>
<green>0.1</green>
<blue>0.1</blue>
<alpha>1.0</alpha>
</color>
<size>
<x>640</x>
<y>480</y>
<w>0</w>
<h>0</h>
</size>
<mode fullscreen="false">screen mode</mode>
</config>
三、刪除節點(diǎn)
[cpp] view plaincopy
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_print.hpp"
#include<iostream>
using namespace rapidxml;
int main()
{
file<> fdoc("config.xml");
xml_document<> doc;
doc.parse<0>(fdoc.data());
std::string text;
rapidxml::print(std::back_inserter(text), doc, 0);
std::cout<<text<<std::endl;
xml_node<>* root = doc.first_node();
xml_node<>* sec = root->first_node();
root->remove_node(sec); //移除根節點(diǎn)下的sec結點(diǎn)(包括該結點(diǎn)下所有結點(diǎn))
text="刪除一個(gè)節點(diǎn)\r\n";
rapidxml::print(std::back_inserter(text), doc, 0);
std::cout<<text<<std::endl;
root->remove_all_nodes(); //移除根節點(diǎn)下所有結點(diǎn)
text="刪除所有節點(diǎn)\r\n";
rapidxml::print(std::back_inserter(text), doc, 0);
std::cout<<text<<std::endl;
std::ofstream out("test.xml");
out<<doc;
system("pause");
return 0;
}
輸出信息如下:
[html] view plaincopy
<config>
<color>
<red>0.1</red>
<green>0.1</green>
<blue>0.1</blue>
<alpha>1.0</alpha>
</color>
<size>
<x>640</x>
<y>480</y>
<w>0</w>
<h>0</h>
</size>
<mode fullscreen="false">screen mode</mode>
</config>
刪除一個(gè)節點(diǎn)
<config>
<size>
<x>640</x>
<y>480</y>
<w>0</w>
<h>0</h>
</size>
<mode fullscreen="false">screen mode</mode>
</config>
刪除所有節點(diǎn)
<config/>
四、編輯節點(diǎn)信息
暫時(shí)找到的編輯方法就是先刪除再增加
[cpp] view plaincopy
#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"
#include "rapidxml/rapidxml_print.hpp"
#include<iostream>
using namespace rapidxml;
int main()
{
file<> fdoc("config.xml");
std::cout<<fdoc.data()<<std::endl;
xml_document<> doc;
doc.parse<0>(fdoc.data());
std::cout<<doc.name()<<std::endl;
//! 獲取根節點(diǎn)
xml_node<>* root = doc.first_node();
xml_node<>* delnode = root->first_node("color");
root->remove_node(delnode);//先刪除address節點(diǎn)
//
xml_node<>* lnode = root->first_node("size");//找到post節點(diǎn)
xml_node<>* mynode=doc.allocate_node(node_element,"address","河北");
root->insert_node(lnode,mynode);
std::string text;
rapidxml::print(std::back_inserter(text),doc,0);
std::cout<<text<<std::endl;
std::ofstream out("version.xml");
out << doc;
system("pause");
return 0;
}
輸出如下:
[html] view plaincopy
<config>
<color>
<red>0.1</red>
<green>0.1</green>
<blue>0.1</blue>
<alpha>1.0</alpha>
</color>
<size>
<x>640</x>
<y>480</y>
<w>0</w>
<h>0</h>
</size>
<mode fullscreen="false">screen mode</mode>
</config>
<config>
<address>河北</address>
<size>
<x>640</x>
<y>480</y>
<w>0</w>
<h>0</h>
</size>
<mode fullscreen="false">screen mode</mode>
</config>
五、遍歷所有節點(diǎn)
[cpp] view plaincopy
for(rapidxml::xml_node<char> * node = parent_node->first_node("node name");
node != NULL;
node = node->next_sibling())
{
...
}
六、遍歷所有屬性
[cpp] view plaincopy
for(rapidxml::xml_attribute<char> * attr = node->first_attribute("node name");
attr != NULL;
attr = attr->next_attribute())
{
char * value = attr->value();
}
七、gcc使用-std=gnu++0x 編譯rapidxml時(shí)會(huì )報錯,錯誤信息大概如下
...rapidxml_print.hpp:120:23: error:
call to function 'print_element_node' thatis neither visible in the
template definition nor found byargument-dependent lookup
out = print_element_node(out, node, flags,indent);
^
...rapidxml_print.hpp:242:22: note:
'print_element_node' should be declaredprior to the call site or in
namespace 'rapidxml'
inline OutIt print_element_node(OutIt out,const xml_node<Ch> ...
在這里找到了解決方法。
經(jīng)查,原來(lái)print_node()函數被其他函數調用,但在卻未定義(在被調用函數后定義了),所以解決方法為把print_node()函數移到print_children(), print_element_node() 等函數的后面。在原定義處就留一個(gè)函數聲明就行。
具體diff文件如下。
[plain] view plaincopy
Index: rapidxml_print.hpp
===================================================================
--- rapidxml_print.hpp  (revision 2025)
+++ rapidxml_print.hpp  (revision 2080)
@@ -101,68 +101,9 @@
///////////////////////////////////////////////////////////////////////////
// Internal printing operations
-
-        // Print node
+
template<class OutIt, class Ch>
-        inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
-        {
-            // Print proper node type
-            switch (node->type())
-            {
-
-            // Document
-            case node_document:
-                out = print_children(out, node, flags, indent);
-                break;
-
-            // Element
-            case node_element:
-                out = print_element_node(out, node, flags, indent);
-                break;
-
-            // Data
-            case node_data:
-                out = print_data_node(out, node, flags, indent);
-                break;
-
-            // CDATA
-            case node_cdata:
-                out = print_cdata_node(out, node, flags, indent);
-                break;
-
-            // Declaration
-            case node_declaration:
-                out = print_declaration_node(out, node, flags, indent);
-                break;
-
-            // Comment
-            case node_comment:
-                out = print_comment_node(out, node, flags, indent);
-                break;
-
-            // Doctype
-            case node_doctype:
-                out = print_doctype_node(out, node, flags, indent);
-                break;
-
-            // Pi
-            case node_pi:
-                out = print_pi_node(out, node, flags, indent);
-                break;
-
-                // Unknown
-            default:
-                assert(0);
-                break;
-            }
-
-            // If indenting not disabled, add line break after node
-            if (!(flags & print_no_indenting))
-                *out = Ch('\n'), ++out;
-
-            // Return modified iterator
-            return out;
-        }
+        inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent);
// Print children of the node
template<class OutIt, class Ch>
@@ -372,7 +313,69 @@
*out = Ch('>'), ++out;
return out;
}
+
+        // Print node
+        template<class OutIt, class Ch>
+        inline OutIt print_node(OutIt out, const xml_node<Ch> *node, int flags, int indent)
+        {
+            // Print proper node type
+            switch (node->type())
+            {
+            // Document
+            case node_document:
+                out = print_children(out, node, flags, indent);
+                break;
+
+            // Element
+            case node_element:
+                out = print_element_node(out, node, flags, indent);
+                break;
+
+            // Data
+            case node_data:
+                out = print_data_node(out, node, flags, indent);
+                break;
+
+            // CDATA
+            case node_cdata:
+                out = print_cdata_node(out, node, flags, indent);
+                break;
+
+            // Declaration
+            case node_declaration:
+                out = print_declaration_node(out, node, flags, indent);
+                break;
+
+            // Comment
+            case node_comment:
+                out = print_comment_node(out, node, flags, indent);
+                break;
+
+            // Doctype
+            case node_doctype:
+                out = print_doctype_node(out, node, flags, indent);
+                break;
+
+            // Pi
+            case node_pi:
+                out = print_pi_node(out, node, flags, indent);
+                break;
+
+                // Unknown
+            default:
+                assert(0);
+                break;
+            }
+
+            // If indenting not disabled, add line break after node
+            if (!(flags & print_no_indenting))
+                *out = Ch('\n'), ++out;
+
+            // Return modified iterator
+            return out;
+        }
+
}
//! \endcond
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
UNICODE模式下使用rapidxml寫(xiě)xml文件
XML解析筆記
python xml.dom模塊解析xml
C#:XML操作類(lèi)
通過(guò)DOM操作XML數據
XML認證教程,第 9 部分:DOM
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久