实习随手记-用相关解析器解析XML档
来源:互联网 发布:小米的免费网络短信 编辑:程序博客网 时间:2024/06/08 00:47
<
了解常用的C++xml解析器(这里只提供2种常用的)
http://pugixml.org/
http://www.grinninglizard.com/tinyxml/
https://github.com/leethomason/tinyxml2
xml解析还有Cmarkup、rapidxml等这里就不一一提供了,选择一种适合自己的即可,推荐pugixml
>#include"pugiconfig.hpp"
#include"pugixml.hpp"#include<stdio.h>
#include<iostream>
#include<tchar.h>
using namespace std;
int main()
{
const std::wstring strFilePath = _T("test.xml");
pugi::xml_document doc;
doc.load_file(strFilePath.c_str(),pugi::parse_default,pugi::encoding_utf8);
//pugi::xml_document doc;
//if (!doc.load_file("test.xml")) return -1;
//================================[code_traverse_base_basic====================
pugi::xml_node IP = doc.child("NetConfig").child("IP");
std::cout << IP.name()<<endl;
for (pugi::xml_node IPele = IP.first_child(); IPele ; IPele = IPele.next_sibling())
{
for (pugi::xml_attribute attr = IPele.first_attribute(); attr; attr = attr.next_attribute())
{
std::cout << " " << attr.name() << "=" << attr.value()<<" ";//输出IP下面每个标签里的< "属性名=属性值">
}
std::cout << IPele.first_child().value()<<endl;//输出IP地址
}
//=================================
pugi::xml_node URL = doc.child("NetConfig").child("URL");
std::cout << URL.name()<<endl;
for (pugi::xml_node URLele = URL.first_child(); URLele; URLele = URLele.next_sibling())
{
for (pugi::xml_attribute attr = URLele.first_attribute(); attr; attr = attr.next_attribute())
{
std::cout << " " << attr.name() << "=" << attr.value() << " ";
}
std::cout << URLele.first_child().value() << endl;
}
//===========================================
pugi::xml_node ipSeg = doc.child("NetConfig").child("ipSeg");
std::cout << ipSeg.name() << endl;
for (pugi::xml_node ipSegele = ipSeg.first_child(); ipSegele; ipSegele = ipSegele.next_sibling())
{
for (pugi::xml_attribute attr = ipSegele.first_attribute(); attr; attr = attr.next_attribute())
{
std::cout << " " << attr.name() << "=" << attr.value() << " ";
}
//std::cout << ipSegele.first_child().value() << endl;
for (pugi::xml_node ipSegelePlus = ipSegele.first_child(); ipSegelePlus; ipSegelePlus = ipSegelePlus.next_sibling())
{
std::cout << ipSegelePlus.first_child().value() << endl;
}
}
getchar();
}
阅读全文
0 0
- 实习随手记-用相关解析器解析XML档
- android 随手记 dom解析
- #随手记#fastjson 解析数据
- Java解析xml相关
- xml解析相关
- xml解析相关总结
- 实习随手记-
- 实习随手记-注册表
- XML解析器及相关概念介绍
- XML解析及相关问题
- 用PULL解析器解析XML文件
- 用PULL解析器解析XML文件
- Pull解析器解析XML
- pull解析器解析xml
- XML解析器——expat相关文章
- 解析xml文件用spinner显示相关问题
- 解析一个XML文件: XML解析器
- VC6中XML解析相关笔记
- AWS CodeCommit 常见问题
- artoolkit学习之ARSimpleNativeCarsProj的一点研究心得
- 静态方法与单例模式的区别
- MonggoDB 入门
- springboot整合freemarker
- 实习随手记-用相关解析器解析XML档
- Linux services operation list
- Android中APK直接通过JNI访问驱动
- Centos系统使用代理上网设置
- Java的Spi机制心得
- Android中的单位转换代码
- codeforces812BB. Sagheer, the Hausmeister
- oracle 11.2删除节点
- 求正整数的质因子