xml文件的解析

1. xml文件的解析

 1 void CDataMgr::readStringData()
 2 {
 3 std::string xml_name = "config/string.xml";
 4 TiXmlDocument * xmlDoc = new TiXmlDocument( xml_name.c_str() );
 5 unsigned long nLength = 0;
 6 char * pBuffer = ( char * )cocos2d::CCFileUtils::sharedFileUtils()->getFileData( xml_name.c_str(),"rb", &nLength );
 7 xmlDoc->loadMemory( pBuffer, nLength );
 8 
 9 int index = 0;
10 TiXmlElement * RootElement = xmlDoc->RootElement();
11 for ( TiXmlElement * rootelement = RootElement->FirstChildElement(); rootelement != 0; rootelement = rootelement->NextSiblingElement() )
12 {
13 if ( index == 0 ) { index ++; continue; }
14 
15 int id = 0;
16 rootelement->QueryIntAttribute( "id", &id );
17 std::string value = rootelement->Attribute( "value" );
18 mMapString[ id ] = value;
19 }
20 CC_SAFE_DELETE( pBuffer );
21 delete xmlDoc;
22 }
原文地址:https://www.cnblogs.com/alenoscar/p/4353182.html