用TinyXml2读取XML文件的一个简单Demo
2013-09-06 21:37
316 查看
废话少说直接上代码,需要的人自然一看便懂,对于第一次接触TinyXml2的人来说还是有帮助的.
程序运行结果如下:
<?xml version="1.0"?> <Table name="PersonInfo"> <Person Type="学生"> <Age age = "年龄">18</Age> <Height Hei = "身高">1.7</Height> </Person> <Person Type="教师"> <Age age = "年龄">28</Age> <Height Hei = "身高">1.6</Height> </Person> <Person Type="警察"> <Age age = "年龄">30</Age> <Height Hei = "身高">1.8</Height> </Person> </Table>
tinyxml2::XMLDocument Doc; Doc.LoadFile("Test.xml"); tinyxml2::XMLElement *pRoot=Doc.RootElement();//获取根节点 tinyxml2::XMLElement *pNode=pRoot->FirstChildElement("Person"); while (pNode) { tinyxml2::XMLElement *pChildNode=pNode->FirstChildElement();//获取第一个值为Value的子节点 默认返回第一个子节点 const char* pContent; const tinyxml2::XMLAttribute *pAttributeOfNode = pNode->FirstAttribute();//获取第一个属性值 std::cout<< pAttributeOfNode->Value()<<":"; while(pChildNode) { pContent=pChildNode->GetText(); std::cout<<pChildNode->FirstAttribute()->Value()<<":"<<pContent<<" "; pChildNode=pChildNode->NextSiblingElement(); } std::cout<<std::endl; pNode=pNode->NextSiblingElement(); }
程序运行结果如下:
学生:年龄:18 身高:1.7 教师:年龄:28 身高:1.6 警察:年龄:30 身高:1.8
相关文章推荐
- 用TinyXml2读取XML文件的一个简单Demo
- 简单的使用自动化技术实现用WORD读取一个XML文件的过程~
- 一个用java读取XML文件的简单方法(转)
- 使用dom4j最简单的读取一个xml文件的内容
- [JAVA] 一个用java读取XML文件的简单方法
- 一个简单的读取文件的Demo
- 关于如何读取XML文件的一个简单方法
- LUA读取CSV文件的一个简单Demo
- vc 读取 XML文件的一个简单实例,以备查用
- [每天一个demo]用c#实现简单的上传文件程序
- Intellijidea2017.03版创建一个简单的Servlet的demo
- 一个简单的webservice的demo(下)winform异步调用webservice
- Dubbo入门---搭建一个最简单的Demo框架
- [stm32] 一个简单的stm32vet6驱动的天马4线SPI-1.77寸LCD彩屏DEMO
- WCF学习笔记(一)创建一个简单的Demo
- 一个使用JDOM读取XML文件的工具类
- 一个简单demo让你明白真正的‘响应式设计、em、文字图标svg’
- 一个简单的Socket通信Demo
- 一个简单的demo学习Android远程Service(AIDL的使用)
- gulp安装+一个超简单入门小demo