将文件读取到buffer里面才是王道。附上代码,当经验分享了~
//Parse XML file
TinyXML::XMLDocument doc;
unsigned char* pBuffer = NULL;
unsigned long bufferSize = 0;
pBuffer = CCFileUtils::sharedFileUtils()->getFileData("dream.xml", "r", &bufferSize);
if (pBuffer)
{
doc.Parse((const char*)pBuffer);
const char *pHelloString = doc.FirstChildElement("Hello")->GetText();
CCLabelTTF *pHello = CCLabelTTF::create(pHelloString,"Arial",24);
pHello->setPosition(ccp(size.width/4, size.height/4));
this->addChild(pHello,1);
}
//Parse XML file
TinyXML::XMLDocument doc;
unsigned char* pBuffer = NULL;
unsigned long bufferSize = 0;
pBuffer = CCFileUtils::sharedFileUtils()->getFileData("dream.xml", "r", &bufferSize);
if (pBuffer)
{
doc.Parse((const char*)pBuffer);
const char *pHelloString = doc.FirstChildElement("Hello")->GetText();
CCLabelTTF *pHello = CCLabelTTF::create(pHelloString,"Arial",24);
pHello->setPosition(ccp(size.width/4, size.height/4));
this->addChild(pHello,1);
}