Jump to content

Useful Function:getXMLNodes


laserlaser

Recommended Posts

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

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

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