??xml version="1.0" encoding="utf-8" standalone="yes"?>
TinyXML 官网
http://sourceforge.net/projects/tinyxml/
在TinyXML中,Ҏ(gu)XML的各U元素来定义?jin)一些类Q?br />TiXmlBaseQ整个TinyXML模型的基cR?br />TiXmlAttributeQ对应于XML中的元素的属性?br />TiXmlNodeQ对应于DOMl构中的节点?br />TiXmlCommentQ对应于XML中的注释
TiXmlDeclarationQ对应于XML中的x部分Q如Q?lt;?xml version="1.0" encoding="UTF-8"?>
TiXmlDocumentQ对应于XML的整个文?br />TiXmlElementQ对应于XML的元素?br />TiXmlTextQ对应于XML的文字部?br />TiXmlUnknownQ对应于XML的未知部分?br />TiXmlHandlerQ定义了(jin)针对XML的一些操作?br />
关键宏:(x)TIXML_USE_STL
我是直接在tinyxml.h 中直?nbsp;#define TIXML_USE_STL
//xml文
<?xml version="1.0" standalone="no" ?>
<!-- Our to do list data -->
<ToDo>
<!-- Do I need a secure PDA? -->
<Item priority="1" distance="close">菜单1
<bold>Toy store!</bold>
</Item>
<Item priority="2" distance="none">菜单2</Item>
<Item priority="2" distance="far & back">Look for Evil Dinosaurs!</Item>
</ToDo>
*/
#include <stdio.h>
using namespace std;
#include "tinyxml.h"
int main()
{
int nVale ;
int nRet ;
string strValue;
TiXmlDocument doc( "demotest.xml" );
bool loadOkay = doc.LoadFile();
if ( !loadOkay )
{
printf( "Could not load test file 'demotest.xml'. Error='%s'. Exiting.\n", doc.ErrorDesc() );
exit( 1 );
}
TiXmlNode* node = 0;
TiXmlElement* rootElement = 0;
TiXmlElement* itemElement = 0;
TiXmlElement* childElement = 0;
rootElement = doc.RootElement();
assert( rootElement );
cout << rootElement->Value() << endl;
itemElement = rootElement->FirstChildElement();
cout << itemElement->Value() << endl;
cout << itemElement->FirstAttribute()->Value() << endl;
nRet = itemElement->QueryIntAttribute("priority",&nVale);
if (nRet==0) {
cout << nVale << endl;
}
nRet = itemElement->QueryStringAttribute("distance",&strValue);
if (nRet==0) {
cout << strValue << endl;
}
strValue = itemElement->GetText();
cout << strValue << endl;
childElement = itemElement->FirstChildElement();
if (childElement!=NULL)
{
strValue = childElement->Value();
cout << strValue << endl;
strValue = childElement->GetText();
cout << strValue << endl;
}
itemElement = itemElement->NextSiblingElement();
assert(itemElement);
strValue = itemElement->GetText();
cout << strValue << endl;
return 0;
}
]]>