Guest Posted December 3, 2012 Share Posted December 3, 2012 Hi everyone ! How do I get all the attribute values? By the following example retrieves only the first attribute values: local meta = xmlLoadFile ( "vehicles.map" ) local info = xmlFindChild ( meta, "veh", 0 ) local attrs = xmlNodeGetAttributes ( info ) for name, value in pairs ( attrs ) do if name == "R" then outputChatBox(value) end end Link to comment
myonlake Posted December 3, 2012 Share Posted December 3, 2012 Perhaps this is what you want. Server-side local xml = xmlLoadFile("vehicles.map") for index,vehicle in ipairs(xmlNodeGetChildren(xml, "veh")) do if xmlNodeGetAttribute(vehicle, "name") == "R" then outputChatBox("ID: " .. index .. ".", root, 255, 255, 255, false) xmlUnloadFile(xml) break end end Please note that this is server-side. The reason is, because otherwise it would receive information from the client instead of the server. Link to comment
Guest Posted December 4, 2012 Share Posted December 4, 2012 Error: Bad argument #1 to 'ipairs' for index, vehicle in ipairs( xmlNodeGetChildren(xml, "veh") ) do Link to comment
myonlake Posted December 4, 2012 Share Posted December 4, 2012 Error: Bad argument #1 to 'ipairs' for index, vehicle in ipairs( xmlNodeGetChildren(xml, "veh") ) do Because your map file doesn't include any nodes. You need to have at least one node to make it work. Link to comment
Guest Posted December 4, 2012 Share Posted December 4, 2012 I did so: local xml = xmlLoadFile("vehicles.map") local child = xmlNodeGetChildren(xml) for index, vehicle in ipairs ( child ) do outputChatBox("ID: " .. xmlNodeGetAttribute(vehicle, "R") .. ".", root, 255, 255, 255, false) end xmlUnloadFile(xml) It worked ! Thank you Link to comment
myonlake Posted December 4, 2012 Share Posted December 4, 2012 Oh... weird. My scripts never used that and they still worked but thanks for the info. You're welcome though Link to comment
Guest Posted December 6, 2012 Share Posted December 6, 2012 Why did not charge me a parent attribute value posX1? http://pastebin.com/uaCyACHE Link to comment
Guest Posted December 11, 2012 Share Posted December 11, 2012 How do I get the parent of the attribute 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