设为首页 加入收藏

TOP

读xml生成代码例子(二)
2015-07-24 10:52:21 来源: 作者: 【 】 浏览:2
Tags:xml 生成 代码 例子
attr->Name(), "name")==0) { name = attr->Value(); string fristStr = name.substr(0,1); string wirteStr = "function read_" + name + "(is)"; if(strcmp(fristStr.c_str(), "C")== 0 ) { isRead = false; wirteStr = "function send_" + name + "(self)"; } file << wirteStr ; }else if(strcmp(attr->Name(), "description")==0) { file << " --" << attr->Value() << endl; if (!isRead) { file << "\tlocal " + name + " = " + id + " --" + attr->Value() << endl; file << "\tlocal sendData = ByteArrayOutputStream()" << endl; file << "\tsendData:writeInt(" + id + ")" << endl; } } attr = attr->Next(); //获取下一个属性值 } XMLElement *surface1 = surface->FirstChildElement(); //查看当前对象是否有子节点 if(surface1) { if(isRead) { file << "\tlocal data = {}" << endl; read_S_ElementChild(surface1);//递归调用 }else { read_C_ElementChild(surface1); } } if (isRead) { file << "\treturn data" << endl; }else { file << "\tsendDataStream(sendData)" << endl; } file << "end" << endl; file << endl; surface = surface->NextSiblingElement();//当前对象的下一个节点 } } int main() { if(!file) { std::cout<<"文件打开失败!"; abort();//等同于exit } tinyxml2::XMLDocument mydocument; //声明xml对象 mydocument.LoadFile("protocol.xml"); //载入xml文件 XMLElement *rootElement = mydocument.RootElement(); //获取跟节点 XMLElement *surface = rootElement->FirstChildElement("message");//获取第一个值为value的子节点 默认为空则返回第一个节点 read_xml(surface); file.close(); cin.get(); }

xml

	
		
		
	

	
		
		
	

生成效果:

lua

function read_S_ITEM_ADD_TASK(is)  --向背包添加一种任务道具
	local data = {}
	data.task_max = is:readInt()  --任务道具包裹的当前长度(可能有空格)
	local cnt = is:readShort()
	local temps = {}
	for i=1, cnt do
		temps[i] = read_S_ITEM_TASKPROPS(is)
	end
	data.items = temps  --数据

	return data
end

function send_C_MAP_NODE_ARRIVE(self)  --角色到达结点
	local C_MAP_NODE_ARRIVE = 0x02000006  --角色到达结点
	local sendData = ByteArrayOutputStream()
	sendData:writeInt(0x02000006)
	local param0 = tonumber(self:getExtraValue(0))
	sendData:writeInt(param0)  --关卡结点id
	local param1 = self:getExtraValue(1)
	sendData:writeBool(param1)  --是否到达终点
	sendDataStream(sendData)
end

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORACLE定时执行存储过程常用时间.. 下一篇OLAP的学习与实例搭建

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)