Jump to content

Help XML


Jacobob14

Recommended Posts

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

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

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

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...