废话少说直接上代码,需要的人自然一看便懂,对于第一次接触TinyXml2的人来说还是有帮助的.
18
1.7
28
1.6
30
1.8
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<FirstAttribute()->Value()<
pChildNode=pChildNode->NextSiblingElement();
}
std::cout<<:endl>
pNode=pNode->NextSiblingElement();
}
程序运行结果如下:
学生:年龄:18 身高:1.7
教师:年龄:28 身高:1.6
警察:年龄:30 身高:1.8
本人郑重声明如下
二、All Rights Reserved. 任何个人或网站转载本文时不得移除本声明.
三、不得对文章进行修改,除非明确说明.同时欢迎大家评论转载和分享.