Engine/Scripting/LuaBind.cpp
void XML_ParseNode (lua_State* L, TiXmlNode* xmlNode)
{
	if (!xmlNode) return;
	// resize stack if neccessary
	luaL_checkstack(L, 5, "XML_ParseNode : recursion too deep");
	
	TiXmlElement* xmlElement = xmlNode->ToElement();
	if (xmlElement)
	{
		// element name
		lua_pushstring(L, "name");
		lua_pushstring(L, xmlElement->Value());
		lua_settable(L, -3);
		
		// parse attributes
		TiXmlAttribute* xmlAttribute = xmlElement->FirstAttribute();
		if (xmlAttribute)
		{
			lua_pushstring(L, "attr");
			lua_newtable(L);
			for (; xmlAttribute; xmlAttribute = xmlAttribute->Next())
			{
				lua_pushstring(L, xmlAttribute->Name());
				lua_pushstring(L, xmlAttribute->Value());
				lua_settable(L, -3);
				
			}
			lua_settable(L, -3);
		}
	}
	
	// children
	TiXmlNode *child = xmlNode->FirstChild();
	if (child)
	{
		int childCount = 0;
		for(; child; child = child->NextSibling())
		{
			switch (child->Type())
			{
				case TiXmlNode::DOCUMENT:
					break;
				case TiXmlNode::ELEMENT: 
					// normal element, parse recursive
					lua_newtable(L);
					XML_ParseNode(L, child);
					lua_rawseti(L, -2, ++childCount);
				break;
				case TiXmlNode::COMMENT: break;
				case TiXmlNode::TEXT: 
					// plaintext, push raw
					lua_pushstring(L, child->Value());
					lua_rawseti(L, -2, ++childCount);
				break;
				case TiXmlNode::DECLARATION: break;
				case TiXmlNode::UNKNOWN: break;
			};
		}
		lua_pushstring(L, "n");
		lua_pushnumber(L, childCount);
		lua_settable(L, -3);
	}
}
// XML code based on code from lua-users.org
XML code based on code from lua-users.org
XML code based on code from lua - users . org
void XML_ParseNode (lua_State* L, TiXmlNode* xmlNode)
{
	if (!xmlNode) return;
	luaL_checkstack(L, 5, "XML_ParseNode : recursion too deep");
	TiXmlElement* xmlElement = xmlNode->ToElement();
	if (xmlElement)
	{
		lua_pushstring(L, "name");
		lua_pushstring(L, xmlElement->Value());
		lua_settable(L, -3);
		TiXmlAttribute* xmlAttribute = xmlElement->FirstAttribute();
		if (xmlAttribute)
		{
			lua_pushstring(L, "attr");
			lua_newtable(L);
			for (; xmlAttribute; xmlAttribute = xmlAttribute->Next())
			{
				lua_pushstring(L, xmlAttribute->Name());
				lua_pushstring(L, xmlAttribute->Value());
				lua_settable(L, -3);
			}
			lua_settable(L, -3);
		}
	}
	TiXmlNode *child = xmlNode->FirstChild();
	if (child)
	{
		int childCount = 0;
		for(; child; child = child->NextSibling())
		{
			switch (child->Type())
			{
				case TiXmlNode::DOCUMENT:
					break;
				case TiXmlNode::ELEMENT: 
					lua_newtable(L);
					XML_ParseNode(L, child);
					lua_rawseti(L, -2, ++childCount);
				break;
				case TiXmlNode::COMMENT: break;
				case TiXmlNode::TEXT: 
					lua_pushstring(L, child->Value());
					lua_rawseti(L, -2, ++childCount);
				break;
				case TiXmlNode::DECLARATION: break;
				case TiXmlNode::UNKNOWN: break;
			};
		}
		lua_pushstring(L, "n");
		lua_pushnumber(L, childCount);
		lua_settable(L, -3);
	}
}
void XML_ParseNode ( lua_State * L , TiXmlNode * xmlNode ) { if ( ! xmlNode ) return ; luaL_checkstack ( L , 5 , " " ) ; TiXmlElement * xmlElement = xmlNode -> ToElement ( ) ; if ( xmlElement ) { lua_pushstring ( L , " " ) ; lua_pushstring ( L , xmlElement -> Value ( ) ) ; lua_settable ( L , -3 ) ; TiXmlAttribute * xmlAttribute = xmlElement -> FirstAttribute ( ) ; if ( xmlAttribute ) { lua_pushstring ( L , " " ) ; lua_newtable ( L ) ; for ( ; xmlAttribute ; xmlAttribute = xmlAttribute -> Next ( ) ) { lua_pushstring ( L , xmlAttribute -> Name ( ) ) ; lua_pushstring ( L , xmlAttribute -> Value ( ) ) ; lua_settable ( L , -3 ) ; } lua_settable ( L , -3 ) ; } } TiXmlNode * child = xmlNode -> FirstChild ( ) ; if ( child ) { int childCount = 0 ; for ( ; child ; child = child -> NextSibling ( ) ) { switch ( child -> Type ( ) ) { case TiXmlNode :: DOCUMENT : break ; case TiXmlNode :: ELEMENT : lua_newtable ( L ) ; XML_ParseNode ( L , child ) ; lua_rawseti ( L , -2 , ++ childCount ) ; break ; case TiXmlNode :: COMMENT : break ; case TiXmlNode :: TEXT : lua_pushstring ( L , child -> Value ( ) ) ; lua_rawseti ( L , -2 , ++ childCount ) ; break ; case TiXmlNode :: DECLARATION : break ; case TiXmlNode :: UNKNOWN : break ; } ; } lua_pushstring ( L , " " ) ; lua_pushnumber ( L , childCount ) ; lua_settable ( L , -3 ) ; } }
XML code based on code from lua-users.org
XML code based on code from lua - users . org
// resize stack if neccessary // element name // parse attributes // children // normal element, parse recursive // plaintext, push raw