锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
TinyXML 瀹樼綉
http://sourceforge.net/projects/tinyxml/
鍦═inyXML涓紝鏍規嵁XML鐨勫悇縐嶅厓绱犳潵瀹氫箟浜嗕竴浜涚被錛?br />TiXmlBase錛氭暣涓猅inyXML妯″瀷鐨勫熀綾匯?br />TiXmlAttribute錛氬搴斾簬XML涓殑鍏冪礌鐨勫睘鎬с?br />TiXmlNode錛氬搴斾簬DOM緇撴瀯涓殑鑺傜偣銆?br />TiXmlComment錛氬搴斾簬XML涓殑娉ㄩ噴
TiXmlDeclaration錛氬搴斾簬XML涓殑鐢蟲槑閮ㄥ垎錛屽錛?lt;?xml version="1.0" encoding="UTF-8"?>
TiXmlDocument錛氬搴斾簬XML鐨勬暣涓枃妗c?br />TiXmlElement錛氬搴斾簬XML鐨勫厓绱犮?br />TiXmlText錛氬搴斾簬XML鐨勬枃瀛楅儴鍒?br />TiXmlUnknown錛氬搴斾簬XML鐨勬湭鐭ラ儴鍒嗐?br />TiXmlHandler錛氬畾涔変簡閽堝XML鐨勪竴浜涙搷浣溿?br />
鍏抽敭瀹忥細TIXML_USE_STL
鎴戞槸鐩存帴鍦╰inyxml.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;
}
]]>