读取文件以str方法读取:

 
  
  1. //设置文件路径  
  2.         string documentPath = CCFileUtils::sharedFileUtils()->getWriteablePath();  
  3.         string fileName = "test.xml";  
  4.         string filePath = documentPath + fileName;  
  5.         string path = filePath;  
  6.  
  7.         //读怪文件内容,将文件以这符串的形式存入char中  
  8.         unsigned char* pBuffer = NULL;  
  9.         unsigned long bufferSize = 0;  
  10.         pBuffer = CCFileUtils::sharedFileUtils()->getFileData(path.c_str(), "r", &bufferSize); 

用TiXmlDocument方式读取并解析:

 

 
  
  1. //用TiXmlDocument来解析XML  
  2.         TiXmlDocument *myDocument = new TiXmlDocument(path.c_str());  
  3.         myDocument->LoadFile();  
  4.  
  5.         //获得根元素  
  6.         TiXmlElement *RootElement = myDocument->RootElement();  
  7.         //RootElement->Value()  
  8.  
  9.         //获得节点。  
  10.         TiXmlElement *FirstPerson = RootElement->FirstChildElement();  
  11.         //获取节点属性  
  12.         TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();  
  13.         //属性名称  
  14.         //IDAttribute->Name();  
  15.         //属性值  
  16.         //IDAttribute->Value(); 

 这里给大家提供一下tinyXML下载,看附件!