laserlaser Posted November 18, 2010 Share Posted November 18, 2010 Hello,i write a new useful function.This name is getXMLNodes,good! My name is |OS|Bikers! in MTA! The Codes: function getXMLNodes(xmlfile,nodename) local xml = xmlLoadFile(xmlfile) if xml then local ntable={} local a = 0 while xmlFindChild(xml,nodename,a) do table.insert(ntable,a+1) ntable[a+1]={} local attrs = xmlNodeGetAttributes ( xmlFindChild(xml,nodename,a) ) for name,value in pairs ( attrs ) do table.insert(ntable[a+1],name) ntable[a+1][name]=value end ntable[a+1]["nodevalue"]=xmlNodeGetValue(xmlFindChild(xml,nodename,a)) a=a+1 end return ntable else return {} end end Example USE: local aTeam = getXMLNodes("teams.xml","team") for ka,vc in ipairs(aTeam) do outputDebugString(vc.tag) end Made in Turkey! War of Empire LUA TEAM! Link to comment
greacius Posted November 18, 2010 Share Posted November 18, 2010 Oke... what's so usefull about this...? Link to comment
laserlaser Posted November 18, 2010 Author Share Posted November 18, 2010 Oke... what's so usefull about this...? Time to good use,More quickly...There is no unnecessary code Ty for reply my topic Link to comment
dzek (varez) Posted November 18, 2010 Share Posted November 18, 2010 You can put this on MTA wiki if you want. https://wiki.multitheftauto.com/wiki/Useful_Functions Link to comment
laserlaser Posted November 18, 2010 Author Share Posted November 18, 2010 You can put this on MTA wiki if you want.https://wiki.multitheftauto.com/wiki/Useful_Functions yes i want but how to ? Link to comment
dzek (varez) Posted November 18, 2010 Share Posted November 18, 2010 You need to login with Open ID to wiki (click "Log in with OpenID" on the top-right). Before you need to have Open ID account. if you dont have it - register it for example: here (btw: according to existing xml functions it will be better to name your function xmlGetNodes) after login go to: https://wiki.multitheftauto.com/wiki/XmlGetNodes and press "edit" link. if you dont know anything about wiki syntax, you can check another function wiki source (like this one - result) fill your function page, and save it. you are done. Link to comment
greacius Posted November 18, 2010 Share Posted November 18, 2010 Oke... but it only gets the value, not the attributes, and what if there isnt any value? Link to comment
laserlaser Posted November 18, 2010 Author Share Posted November 18, 2010 Oke... but it only gets the value, not the attributes, and what if there isnt any value? if there isn't any value return "" else return node value if there isn't any attr then return table hasn't attr Link to comment
Callum Posted November 18, 2010 Share Posted November 18, 2010 It's more efficient to do a loop for the XML children, instead of looping a table, which used another loop to be generated. 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