Jump to content

xml get by name


ahmedo01

Recommended Posts

i'm created xml file.

xml file =

<playervehicles> 
    <vehicle vehicleid="450" owner="Ahmet" r="1" g="1" b="1"></vehicle> 
    <vehicle vehicleid="450" owner="Other" r="0" g="15" b="0"></vehicle> 
    <vehicle vehicleid="450" owner="Ahmet" r="1" g="1" b="1"></vehicle> 
    <vehicle vehicleid="402" owner="Ahmet" r="1" g="1" b="1"></vehicle> 
</playervehicles> 

how i can get children by owner.

Link to comment
local xmlPath = "myXMLfile.xml" 
  
function getVehiclesInXMLByOwner ( owner ) 
    local vehicles = { } -- Define a Lua table 
    if ( owner ) then -- If the argument was passed to the function... 
        local xmlFile = xmlLoadFile ( xmlPath ) -- Load the XML file 
        if ( xmlFile ) then -- If the XML file is loaded 
            for _, child in ipairs ( xmlNodeGetChildren ( xmlFile ) ) do -- Loop all it's children 
                local attrs = xmlNodeGetAttributes ( child ) -- Get the children attributes 
                if ( attrs.owner == owner ) then -- If the owner matches the passed argument 
                    table.insert ( -- Insert it into our 'vehicles' table 
                        vehicles, 
                        { 
                            id = attrs.vehicleid, 
                            r = attrs.r, 
                            g = attrs.g, 
                            b = attrs.b 
                        } 
                    ) 
                end 
            end 
            xmlUnloadFile ( xmlFile ) -- Unload the XML file 
        end 
    end 
  
    return vehicles -- Return the vehicles table 
end 

Try it.

Link to comment

it looks hard. i want list player vehicles in gridlist

client codes

  
xml = xmlLoadFile( "vehicles.xml" ) 
childs = xmlNodeGetChildren( xml ) 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        vehiclepanel = guiCreateWindow(955, 224, 276, 392, "Vehicle Panel", false) 
        guiWindowSetSizable(vehiclepanel, false) 
  
        vehiclelist = guiCreateGridList(10, 111, 256, 195, false, vehiclepanel) 
        guiGridListAddColumn(vehiclelist, "Vehicle List:", 0.9) 
        guiGridListAddRow(vehiclelist) 
        guiGridListSetItemText(vehiclelist, 0, 1, "-", false, false) 
        spawn = guiCreateButton(13, 354, 88, 28, "Spawn", false, vehiclepanel) 
        hide = guiCreateButton(111, 354, 60, 28, "Hide", false, vehiclepanel) 
        cancel = guiCreateButton(181, 354, 85, 28, "Cancel", false, vehiclepanel) 
        track = guiCreateButton(13, 316, 88, 28, "Track", false, vehiclepanel) 
        recover = guiCreateButton(107, 316, 88, 28, "Recover", false, vehiclepanel) 
        sell = guiCreateButton(205, 316, 61, 28, "Sell", false, vehiclepanel) 
        infolabel = guiCreateLabel(10, 31, 246, 70, "Select a vehicle and spawn. You can track, \nrecover, sell, spawn and hide your vehicle.", false, vehiclepanel) 
        guiSetVisible( vehiclepanel, false )     
    end 
  
  
) 
function opengui() 
    local state = guiGetVisible( vehiclepanel ) 
    if state == false then 
        guiSetVisible(vehiclepanel, true) 
        showCursor( true ) 
         
for vehicleid, r, g, b in pairs(attr) do 
    outputChatBox(vehicleid..r..g..b) 
end 
    elseif state == true then 
        guiSetVisible(vehiclepanel, false) 
        showCursor( false ) 
        guiGridListClear ( vehiclelist ) 
    end 
end 
bindKey("F2", "down", opengui) 
  

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