Piorun Posted July 15, 2011 Share Posted July 15, 2011 Hi guys. Today i've got problem with a xml file. Here's my xml file (called veh.xml) "1" modelid="492" owner="Piorun" posx="-712.0078125" posy="962.6455078125" posz="12.342837333679" rotx="0" roty="0" rotz="198.21011352539" stcolor="20" ndcolor="2" plate="plate" /> "2" modelid="429" owner="Piorun" posx="-724.787109375" posy="973.064453125" posz="12.339513778687" rotx="0" roty="0" rotz="339.06796264648" stcolor="0" ndcolor="0" plate="newpl" /> And how to create function witch i can create a car with these values (createVehicle for every child)? Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 local xmlFile = xmlLoadFile("veh.xml") for i, node in ipairs(xmlNodeGetChildren(xmlFile)) do --here this code will happen for each --get the attributes and create your vehicle end Link to comment
Piorun Posted July 15, 2011 Author Share Posted July 15, 2011 hahaha Thanks - working. Link to comment
Piorun Posted July 15, 2011 Author Share Posted July 15, 2011 By the way - i don't understand what to do next: function createVehsFromXML() local xmlfile = xmlLoadFile("veh.xml") for i, node in ipairs(xmlNodeGetChildren(xmlfile)) do local atr = xmlNodeGetAttributes(node) for name,value in pairs ( atr ) do end end end addEventHandler("onResourceStart", getRootElement(), createVehsFromXML) I've got this code, but i don't know how to get first value of 'value', second value of 'value' etc. Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 Well, you shouldn't do xmlNodeGetAttributes, no you should get one one, using xmlNodeGetAttribute Here: function createVehsFromXML() local xmlfile = xmlLoadFile("veh.xml") for i, node in ipairs(xmlNodeGetChildren(xmlfile)) do local modelid = xmlNodeGetAttribute(node, "modelid") local posx = xmlNodeGetAttribute(node, "posx") local posy = xmlNodeGetAttribute(node, "posy") local posz = xmlNodeGetAttribute(node, "posz") local rotx = xmlNodeGetAttribute(node, "rotx") local roty = xmlNodeGetAttribute(node, "roty") local rotz = xmlNodeGetAttribute(node, "rotz") local plate = xmlNodeGetAttribute(node, "plate") createVehicle(tonumber(modelid), tonumber(posx), tonumber(posy), tonumber(posy), tonumber(rotx), tonumber(roty), tonumber(rotz), plate) end end addEventHandler("onResourceStart", resourceRoot, createVehsFromXML) This should work. 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