Jacobob14 Posted August 21, 2015 Share Posted August 21, 2015 as I can do to get the other XML data color and skin id xml "Team1" > "0" green="75" blue="150" /> "287" /> "Team2" > "0" green="0" blue="250" /> "15" /> my script function start() local file = xmlLoadFile ( "datos.xml" ) local children = xmlNodeGetChildren ( file ) for index, node in pairs ( children ) do outputChatBox(xmlNodeGetAttribute ( node, "name" )) end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), start) Link to comment
JR10 Posted August 21, 2015 Share Posted August 21, 2015 local color_node = xmlFindChild(node, 'color', 0) local skin_node = xmlFindChild(node, 'skin', 0) Link to comment
Jacobob14 Posted August 23, 2015 Author Share Posted August 23, 2015 I don't understand how I would use it? something like that function start() local file = xmlLoadFile ( "datos.xml" ) local children = xmlNodeGetChildren ( file ) for index, node in pairs ( children ) do for class, color in pairs ( xmlFindChild(node, 'color', 0) ) do outputChatBox(xmlNodeGetAttribute ( node, "name" )) end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), start) Link to comment
JR10 Posted August 23, 2015 Share Posted August 23, 2015 If there is more than one color child then you can do this to find them all: function start() local file = xmlLoadFile ( "datos.xml" ) local children = xmlNodeGetChildren ( file ) for index, node in pairs ( children ) do local index = 0 while (xmlFindChild(node, 'color', index) do local color_node = xmlFindChild(node, 'color', index) outputChatBox(xmlNodeGetAttribute ( color_node, "red" )) index = index + 1 end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), start) Link to comment
Jacobob14 Posted August 23, 2015 Author Share Posted August 23, 2015 thank you very much for your great help Link to comment
Jacobob14 Posted August 23, 2015 Author Share Posted August 23, 2015 sorry again how could save the data in a table ? I would like to be saved like this format Teams = { ["citizen"] = { red = 0 , green = 100, blue = 40 } } i try something like this but it does not work red = xmlNodeGetAttribute ( teamName, "red" ) teamname = xmlNodeGetAttribute ( node, "name" ) table.insert(Teams, { [ teamname ] = { "red" = red}} ) Link to comment
JR10 Posted August 23, 2015 Share Posted August 23, 2015 local teams = {} function start() local file = xmlLoadFile ( "datos.xml" ) local children = xmlNodeGetChildren ( file ) for index, node in pairs ( children ) do local name = xmlNodeGetAttribute(node, 'name') local index = 0 while (xmlFindChild(node, 'color', index) do local color_node = xmlFindChild(node, 'color', index) local red = xmlNodeGetAttribute ( color_node, "red" ) teams[name] = {"red" = red} index = index + 1 end end end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), start) Though, this doesn't seem logical. If you have more than one color node, it will just be the last one's red value. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now