ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

¶ÁxmlÉú³É´úÂëÀý×Ó(Ò»)
2015-07-24 10:52:21 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºxml Éú³É ´úÂë Àý×Ó

¶ÁxmlÉú³ÉÏàÓ¦µÄ lua½âÎöЭÒé´úÂ룺

#include 
#include "tinyxml2.h"
#include 
#include 

using namespace tinyxml2;
using namespace std;
std::ofstream file("readProto.lua",std::ios::ate|std::ios::binary);

void read_S_ElementChild(XMLElement *surface)
{
	while (surface)
	{
		const XMLAttribute *attr = surface->FirstAttribute();//»ñÈ¡µÚÒ»¸öÊôÐÔÖµ
		string strType;
		bool isArray = false;
		while(attr)
		{
			if (strcmp(attr->Name(), "name")==0)
			{
				string name = attr->Value();
				string dataStr = "data.";
				string temp1 = "\t" + dataStr + name + " = ";
				string temp;
				if(strcmp(strType.c_str(), "String")==0){
					temp =  "is:readUTF8()";
				}else if(strcmp(strType.c_str(), "long")==0){
					temp = "is:readLong()";
				}else if(strcmp(strType.c_str(), "int")==0){
					temp = "is:readInt()";
				}else if(strcmp(strType.c_str(), "short")==0){
					temp = "is:readShort()";
				}else if(strcmp(strType.c_str(), "byte")==0){
					temp = "is:readByte()";
				}else if(strcmp(strType.c_str(), "boolean")==0){
					temp = "is:readBool()";
				}else if(strcmp(strType.c_str(), "float")==0){
					temp = "is:readJavaFloat()";
				}else{
					size_t len = strType.size();
					string lastStr = strType.substr(len-2, 2);
					if(strcmp(lastStr.c_str(), "[]")==0){ //´ú±íÊÇÊý×é
						isArray	= true;
						file << "\tlocal cnt = is:readShort()" << endl;
						file << "\tlocal temps = {}" << endl;
						file << "\tfor i=1, cnt do" << endl;
						string preStr = strType.substr(0, len-2);
						string preStrTemp;
						if(strcmp(preStr.c_str(), "String")==0){
							preStrTemp =  "is:readUTF8()";
						}else if(strcmp(preStr.c_str(), "long")==0){
							preStrTemp = "is:readLong()";
						}else if(strcmp(preStr.c_str(), "int")==0){
							preStrTemp = "is:readInt()";
						}else if(strcmp(preStr.c_str(), "short")==0){
							preStrTemp = "is:readShort()";
						}else if(strcmp(preStr.c_str(), "byte")==0){
							preStrTemp = "is:readByte()";
						}else if(strcmp(preStr.c_str(), "boolean")==0){
							preStrTemp = "is:readBool()";
						}else if(strcmp(preStr.c_str(), "float")==0){
							preStrTemp = "is:readJavaFloat()";
						}else
						{
							preStrTemp = "read_" + preStr + "(is)";
						}
						file << "\t\ttemps[i] = " << preStrTemp << endl;
						file << "\tend" << endl;
					}else{
						temp = "read_" + strType + "(is)";
					}
				}
				if(!isArray){
					file << temp1 + temp;
				}else{ //ÊÇÊý×é
					file << temp1 + "temps" ;
				}
			}else if(strcmp(attr->Name(), "type")==0)
			{
				strType = attr->Value();
				
			}else if(strcmp(attr->Name(), "description")==0)
			{
				string desc = attr->Value();
				string temp = "  --" + desc;
				file << temp << endl;
				if(isArray)
				{
					file << endl;
				}
			}
			attr = attr->Next(); //»ñÈ¡ÏÂÒ»¸öÊôÐÔÖµ
		}
		surface = surface->NextSiblingElement();//µ±Ç°¶ÔÏóµÄÏÂÒ»¸ö½Úµã
	}
}

void read_C_ElementChild(XMLElement *surface)
{
	int i = 0;
	while (surface)
	{
		string strType;
		const XMLAttribute *attr = surface->FirstAttribute();//»ñÈ¡µÚÒ»¸öÊôÐÔÖµ
		while(attr)
		{
			if (strcmp(attr->Name(), "name")==0)
			{
				string temp;
				bool isNum = false;
				string param = "param";
				char num[4]="";
				sprintf_s(num, "%d", i);
				
				if(strcmp(strType.c_str(), "String")==0){
					temp = "sendData:writeUTF8(";
				}else if(strcmp(strType.c_str(), "long")==0){
					isNum = true;
					temp = "sendData:writeLong(";
				}else if(strcmp(strType.c_str(), "int")==0){
					isNum = true;
					temp = "sendData:writeInt(";
				}else if(strcmp(strType.c_str(), "short")==0){
					isNum = true;
					temp = "sendData:writeShort(";
				}else if(strcmp(strType.c_str(), "byte")==0){
					isNum = true;
					temp = "sendData:writeByte(";
				}else if(strcmp(strType.c_str(), "boolean")==0){
					temp = "sendData:writeBool(";
				}else if(strcmp(strType.c_str(), "float")==0){
					isNum = true;
					temp = "sendData:writeJavaFloat(";
				}else{

					temp = "error ############ ";
				}

				if (isNum)
				{
					file << "\tlocal " + param + num + " = tonumber(" + "self:getExtraValue("  + num + "))" << endl;
				}else{
					file << "\tlocal " + param + num + " = " + "self:getExtraValue("  + num + ")" << endl;
				}
				file << "\t" + temp + param + num + ")" ;
			}else if(strcmp(attr->Name(), "type")==0){
				strType = attr->Value();
			}else if(strcmp(attr->Name(), "description")==0){
				file << "  --" << attr->Value() << endl;
			}
			
			attr = attr->Next(); //»ñÈ¡ÏÂÒ»¸öÊôÐÔÖµ
		}
		i = i + 1;
		surface = surface->NextSiblingElement();//µ±Ç°¶ÔÏóµÄÏÂÒ»¸ö½Úµã
	}
}

void read_xml(XMLElement *surface)
{
	while (surface)
	{
		string id;
		string name;
		bool isRead = true;
		const XMLAttribute *attr = surface->FirstAttribute();//»ñÈ¡µÚÒ»¸öÊôÐÔÖµ
		while(attr)
		{
			if(strcmp(attr->Name(), "id")==0)
			{
				id = attr->Value();
			}else if(strcmp(
Ê×Ò³ ÉÏÒ»Ò³ 1 2 ÏÂÒ»Ò³ βҳ 1/2/2
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºORACLE¶¨Ê±Ö´Ðд洢¹ý³Ì³£ÓÃʱ¼ä.. ÏÂһƪ£ºOLAPµÄѧϰÓëʵÀý´î½¨

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Linuxϵͳ¼ò½é (2025-12-25 21:55:25)
¡¤Linux°²×°MySQL¹ý³Ì (2025-12-25 21:55:22)
¡¤Linuxϵͳ°²×°½Ì³Ì£¨ (2025-12-25 21:55:20)
¡¤HTTP Åc HTTPS µÄ²î„ (2025-12-25 21:19:45)
¡¤ÍøÕ¾°²È«±ØÐ޿ΣºÍ¼ (2025-12-25 21:19:42)