xml格式解析
来源:互联网 发布:数据咨询公司是干嘛的 编辑:程序博客网 时间:2024/05/19 18:44
//printf("项目中的xml解析\n");//得到路径const char *path = lua_tostring(L, 1);//得到 最后的表明const char *tableKey = lua_tostring(L, 2);lua_getglobal(L, "cc");lua_getfield(L, -1, "GameArgs");//把路径转为字符流std::string buffer = CCFileUtils::getInstance()->getStringFromFile(path);tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();doc->Parse(buffer.c_str());tinyxml2::XMLElement *root = doc->RootElement();lua_newtable(L);tinyxml2::XMLElement *data = root->FirstChildElement();// 7 具体的value 6 具体的key 5 table 4 key 3 table(value) 2 GameArgs 1 ccwhile (data){//firstEletinyxml2::XMLElement *firstEle = data->FirstChildElement();//keylua_pushnumber(L, atoi(firstEle->FirstChild()->Value()));lua_newtable(L);//<vipLevel type="int" multiLanguage="0">0</vipLevel>while (firstEle){//firstEletinyxml2::XMLNode *node = firstEle->FirstChild();//keylua_pushstring(L, firstEle->Value());// Value//lua_pushstring(L, node->Value());//printf("aaa = %s %s\n", firstEle->Value(), node->Value());const tinyxml2::XMLAttribute *attr = firstEle->FirstAttribute();while (attr){if (strcmp(attr->Name(), "type") == 0 && strcmp(attr->Value(), "int") == 0){lua_pushinteger(L, atoi(node->Value()));}else if ((strcmp(attr->Name(), "type") == 0 && strcmp(attr->Value(), "double") == 0)){lua_pushnumber(L, atof(node->Value()));}else if ((strcmp(attr->Name(), "type") == 0 && strcmp(attr->Value(), "string") == 0) ||(strcmp(attr->Name(), "type") == 0 && strcmp(attr->Value(), "String") == 0)){// 多国语言if (strcmp(attr->Next()->Name(), "multiLanguage") == 0 && strcmp(attr->Next()->Value(), "1") == 0){std::string str = "return ";str += node->Value();lua_pushstring(L, str.c_str());}else if (strcmp(attr->Next()->Name(), "multiLanguage") == 0 && strcmp(attr->Next()->Value(), "0") == 0){char buf[1024];sprintf(buf, "return \"%s\"", node->Value());lua_pushstring(L, buf);}/*lua_pushstring(L, node->Value());*/}attr = attr->Next();}lua_settable(L, -3);firstEle = firstEle->NextSiblingElement();}lua_settable(L, -3);data = data->NextSiblingElement();}lua_setfield(L, -2, tableKey);//t[k] = vdelete doc;return 1;}
printf("lolXMLParse解析\n");//lolRes/lol.xmlconst char *path = lua_tostring(L, -1);//拿到xml解析指针tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();//将文件转为字符流std::string buf = CCFileUtils::getInstance()->getStringFromFile(path);doc->Parse(buf.c_str());//得到roottinyxml2::XMLElement *root = doc->RootElement();lua_newtable(L);//栈 table3 table2 2 id(key) 1 table//得到datatinyxml2::XMLElement *data = root->FirstChildElement();while (data){//得到第一行eletinyxml2::XMLElement *firstEle = data->FirstChildElement();lua_pushnumber(L, atoi(firstEle->FirstChild()->Value()));lua_newtable(L);while (firstEle){tinyxml2::XMLNode *node = firstEle->FirstChild();//printf("heroId = %s idNum = %s\n", firstEle->Value(), node->Value());//keylua_pushstring(L, firstEle->Value());//valuelua_pushstring(L, node->Value());lua_settable(L, -3);firstEle = firstEle->NextSiblingElement();}lua_settable(L, -3);data = data->NextSiblingElement();}return 1;
0 0
- 解析XML格式数据
- NSXMLParser解析xml格式
- XML格式统一解析
- 解析XML格式数据
- 解析XML格式数据文件
- 解析XML格式数据
- IOS 解析XML格式
- 解析XML格式数据
- xml格式解析
- xml格式解析
- 解析XML格式数据
- xml格式数据解析
- xml格式的解析
- 解析XML格式数据
- 解析 XML格式数据
- 解析XML格式,截取节点
- java解析xml格式字符串
- JAVA解析XML格式字符串
- Notification的使用
- Linux查看物理CPU个数、核数、逻辑CPU个数
- Codeforces Round #340 (Div. 2) C. Watering Flowers
- java中文乱码解决之道(四)-----java编码转换过程
- 查看LINUX进程内存占用情况
- xml格式解析
- SQLServer 统计数据量
- 数组——字符串拆为数组及反相
- java中文乱码解决之道(五)-----java是如何编码解码的
- 谁曾是从谁的青春里走过,留下了笑靥
- 视觉词袋模型
- 搜索与机器学习
- 在python3.3后urllib2已经不能再用,只能用urllib.request来代替
- java中文乱码解决之道(六)-----javaWeb中的编码解码