Jump to content

problem with xml?


SirniNamaz

Recommended Posts

client

    if (guiGetVisible(guiEventManager) == true) then 
        local xmlElements = xmlLoadFile("elements.xml") 
        for i=0,149 do 
            local xmlOldChild = xmlFindChild(xmlElements,"element",i) 
            local attrs = xmlNodeGetAttributes(xmlOldChild) 
            if not (attrs == false) then 
                guiGridListClear(grdElementsList) 
                local newRow = guiGridListAddRow(grdElementsList) 
                for name,value in pairs(attrs) do 
                    outputChatBox(name .. " = " .. value) 
                    if (name == "item") then 
                        if (tonumber(value) == 4) then 
                            guiGridListSetItemText(grdElementsList,newRow,colElement2,"Knife",false,false) 
                        end 
                    end 
                    if (name == "x") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2X,value,false,false) 
                    end 
                    if (name == "y") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Y,value,false,false) 
                    end 
                    if (name == "z") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Z,value,false,false) 
                    end 
                    if (name == "left") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Left,value,false,false) 
                    end 
                end 
            end 
        end 
    end 

xml

    "8066072" type="weapon" item="4" x="2486.3376464844" y="-1663.841796875" z="13.335947036743" left="1">
    "7858149" type="weapon" item="4" x="2469.3784179688" y="-1667.8182373047" z="13.302844047546" left="1">

  

the error is : Bad argument @ 'xmlNodeGetAttributes'

Edited by Guest
Link to comment

Be patient, bumping after 1-2 hours and nagging people via PM is NOT nice, really.

for i=0,149 do 
local xmlOldChild = xmlFindChild(xmlElements,"element",i) 

Why are you assuming there's always 149 elements?

With your xml example you will get 147 errors about bad argument @ xmlNodeGetAttributes, because xmlFindChild returns false for them.

Checking if xmlOldChild is false before doing next actions could be good idea, but even better idea would be to use xmlNodeGetChildren, which just gets all children so you don't have to guess how many of them exists.

Link to comment
function eventFiveSec() 
    if (guiGetVisible(guiEventManager) == true) then 
        local xmlElements = xmlLoadFile("elements.xml") 
        for i=0,149 do 
            local xmlOldChild = xmlFindChild(xmlElements,"element",i) 
            local attrs = xmlNodeGetAttributes(xmlOldChild) 
            if (attrs == false) then 
                return 
            else 
                guiGridListClear(grdElementsList) 
                local newRow = guiGridListAddRow(grdElementsList) 
                for name,value in pairs(attrs) do 
                    outputChatBox(name .. " = " .. value) 
                    if (name == "item") then 
                        if (tonumber(value) == 4) then 
                            guiGridListSetItemText(grdElementsList,newRow,colElement2,"Knife",false,false) 
                        end 
                    end 
                    if (name == "x") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2X,value,false,false) 
                    end 
                    if (name == "y") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Y,value,false,false) 
                    end 
                    if (name == "z") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Z,value,false,false) 
                    end 
                    if (name == "left") then 
                        guiGridListSetItemText(grdElementsList,newRow,colElement2Left,value,false,false) 
                    end 
                end 
            end 
        end 
    end 
end 

It now only returns one line of error, but it doesn't get exported to gridlist.

Link to comment

Can't you figure out?

Use the brain and interprete this knowing that "xmlOldChild" returns false:

            local xmlOldChild = xmlFindChild(xmlElements,"element",i) 
            local attrs = xmlNodeGetAttributes(xmlOldChild) 
            if (attrs == false) then 
                return 

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