在用到cocos之前,我已经用rapidxml写了一个小文件读取,成功获取了xml文件的值,但是用到cocos里面时,文件路径设置为
rapidxml::file<> _docl(FileUtils::getInstance()->fullPathForFilename(“pngLink.xml”).c_str());
不会触发rapidxml的断言"cannot open file",
但是读取的数据并没有写好的节点,这是怎么回事,下面是我的函数:
std::string inWhichPlist(char* str)
{
//rapidxml::file<> _docl(FileUtils::getInstance()->fullPathForFilename(“pngLink.xml”).c_str());
rapidxml::xml_node<>* node_pngLink = _doc.first_node("pngLink");
rapidxml::xml_node<>* node_plist = node_pngLink->first_node("plist");
while (node_plist->next_sibling("plist") != NULL)
{
rapidxml::xml_node<>*node_first_sibling = node_plist->first_node("fileName");
for (node_first_sibling; node_first_sibling != NULL; node_first_sibling = node_first_sibling->next_sibling())
{
if (node_first_sibling->value() == str)
{
return (node_plist->first_attribute()->value());
}
}
node_plist = node_plist->next_sibling("plist");//define this to "++"
}
log("ERROR_NOT_FOUND_PNG_IN_PLIST");
return NULL;
}
我如果不用fullPath,把文件放入exe根目录(做测试的时候就这样没问题),会触发runtimeerror,告诉你cannot open file。
我想知道该怎么处理才能正确地读取
附上测试代码:
void main()
{
file<> doc(“land.xml”);
//std::cout << doc.data() << std::endl;
xml_document<> _doc;
_doc.parse<0>(doc.data());
xml_node<>* node_land = _doc.first_node();
if (node_land->first_node("DRY_LAND"))
{
std::cout << node_land->first_node("DRY_LAND")->first_node("id")->value() << std::endl;
}
else
std::cout << "error" << std::endl;
system("pause");
}