码迷,mamicode.com
首页 > 其他好文 > 详细

xml文件的解析

时间:2015-03-20 12:44:12      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

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 }

 

xml文件的解析

标签:

原文地址:http://www.cnblogs.com/alenoscar/p/4353182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!