大家好,又见面了,我是你们的朋友全栈君。
官方地址: 官方手册: 也可以在github上下载到别人上传的rapidxml:
一般我们用到的头文件只有这三个
方法:rapidxml::file<> valName(“filepath”); 定义:rapildxml_print_utils.hpp,这个头文件中定义了file类,这个类有两个成员函数data()和size()分别返回char*的xml文本内容和unsigned int型的文本数据长度 示例:
运行一下!
类:xml_document 定义一个该类的对象doc rapidxml::xml_document<> doc; 类的定义位置:rapidxml.hpp 类的成员函数: 1)parse(Ch *text) 将数据解析为DOM Tree 使用时doc.parse(text); parseFlag指定格式,可以用’|’来组合使用 常用的parseFlag: parseFlag为0表示默认的parseflag parse_comment_nodes表示带上xml中的注释 parse_no_data_nodes在要修改结点值的时候要设置这个parseFlag 2) clear() 清空DOM Tree 此外xml_document继承自xml_node因此还具有xml_node的方法。 示例:
运行一下!
rapidxml::xml_node<> *root; 类:xml_node 定义一个该类的对象root 定义于:rapidxml.hpp 常用的类成员函数: 1)node_type type() const; 获取结点类型 获取的类型是枚举的 2)Ch* name() const; 获取结点名 3)std::size_t name_size() const; 获取结点名长度 4)Ch* value() const; 获取结点值 5)std::size_t value_size() const; 获取结点值长度 6)xml_node* first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取DOM Tree第一个子结点的指针 第一个参数为节点名,如果给定第一个参数为”a”,则该函数寻找结点名为a的第一个子结点;第二个参数为结点名长度 7)xml_node* last_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取DOM Tree最后一个子结点的指针 参数含义同上 8)xml_attribute* first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取结点的第一个属性指针 9)xml_attribute* next_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取结点的下一个属性指针 10)xml_attribute* last_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const;获取结点的最后一个属性指针 属性指针的格式见类xml_attribute 11)xml_node* previous_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const;获取上一个同级结点的指针 12)xml_node* next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取下一个同级结点的指针 13)xml_attribute* first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取第一个同级结点的指针 14)xml_attribute* last_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const; 获取最后一个同级结点的指针 15)void insert_node(xml_node< Ch > *where, xml_node< Ch > *child);在第一个参数指向的结点之前,插入一个结点
示例: test.xml
cpp
运行一下!
类:xml_attribute 定义于:rapidxml.hpp 常用方法: 1)xml_attribute *previous_attribute(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const;获取前一个属性 2)xml_attribute *next_attribute(const Ch *name = 0, std::size_t name_size = 0, bool case_sensitive = true) const;获取后一个属性
1)操作符<< 示例:
运行一下!
1)为结点分配空间 xml_node* allocate_node(node_type type, const Ch *name=0, const Ch *value=0, std::size_t name_size=0, std::size_t value_size=0); 2)为属性分配空间 xml_attribute* allocate_attribute(const Ch *name=0, const Ch *value=0, std::size_t name_size=0, std::size_t value_size=0);
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160916.html原文链接:https://javaforall.cn
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/14266.html