tinyxml2原来 tinyxml升级版版
1、下载
https://sourceforge.net/projects/tinyxml/
https://github.com/leethomason/tinyxml2
2、最新版本 最好在vs2010以上版本运行(包含#include <stdint.h>)
3、vs2008使用tinyxml2 解决办法 下载任意头文件 放到Microsoft Visual Studio 9.0\VC\include 目录即可。
1)、http://www.azillionmonkeys.com/qed/pstdint.h
2)、http://msinttypes.googlecode.com/svn/trunk/stdint.h
或者直接放到工程目录,不过要将tinyxml2.h头文件更改下 #include <stdint.h> 改为 #include "stdint.h"
4、右键工程属性更改编译属性 c/c++ -->预编译头-->不使用预编译头。
5、看示例:
test.xml文件
<?xml version="1.0"?>
<root name="hello">
<item>
<eye>0</eye>
<front>10</front>
</item>
<item>
<center>0 10 -10</center>
<radius>10</radius>
</item>
</root>
6、c++代码:
#include "stdafx.h"
#include "tinyxml2.h"
#include <iostream>
using namespace std;
using namespace tinyxml2;
int main(int argc, char* argv[])
{
XMLDocument doc;
if (doc.LoadFile("test.xml"))
{
doc.PrintError();
exit(1);
}
// 根元素
XMLElement* pRoot = doc.RootElement();
cout << "name:" << pRoot->Attribute("name") << endl << endl;
// 遍历<item>元素
XMLElement* pItem = pRoot->FirstChildElement("item");
while (pItem) {
// 遍历属性列表
const XMLAttribute* surfaceAttr = pItem->FirstAttribute();
while (surfaceAttr)
{
cout << surfaceAttr->Name() << ":" << surfaceAttr->Value() << " ";
surfaceAttr = surfaceAttr->Next();
}
cout << endl;
// 遍历子元素
XMLElement* itemChild = pItem->FirstChildElement();
while (itemChild)
{
cout << itemChild->Name() << " = " << itemChild->GetText() << endl;
itemChild = itemChild->NextSiblingElement();
}
cout << endl;
pItem = pItem->NextSiblingElement("item");
}
return 0;
}