Advertisement
Guest User

LUA

a guest
Jan 25th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. function getXMLData(file, type, childs, attribute)
  2.     if file then
  3.         if attribute then
  4.             if fileExists(file) then
  5.                 childs = split(childs, string.byte(","))
  6.                 if #childs >= 1 then
  7.                     xml = xmlLoadFile(file)
  8.                     if xml then
  9.                         local currentChild = false
  10.                         for i, child in pairs(childs) do
  11.                             if i == #childs and currentChild ~= false then
  12.                                 if type == "value" then
  13.                                     gotValue = xmlNodeGetValue(currentChild)
  14.                                 elseif type == "attribute" then
  15.                                     gotValue = xmlNodeGetAttribute(currentChild, attribute)
  16.                                 end
  17.                                 if gotValue then
  18.                                     xmlUnloadFile(xml)
  19.                                     return gotValue
  20.                                 else
  21.                                     xmlUnloadFile(xml)
  22.                                     outputDebugString("getXMLData - Could not get value/attribute '"..attribute.."'")
  23.                                     return false
  24.                                 end
  25.                             else
  26.                                 currChild = xmlFindChild(xml, child, 0)
  27.                                 if currChild then
  28.                                     currentChild = currChild
  29.                                 else
  30.                                     xmlUnloadFile(xml)
  31.                                     outputDebugString("getXMLData - Could not get child '"..child.."' ("..i..")")
  32.                                     return false
  33.                                 end
  34.                                 if #childs == 1 then
  35.                                     if type == "value" then
  36.                                         gotValue = xmlNodeGetValue(currentChild)
  37.                                     elseif type == "attribute" then
  38.                                         gotValue = xmlNodeGetAttribute(currentChild, attribute)
  39.                                     end
  40.                                     if gotValue then
  41.                                         xmlUnloadFile(xml)
  42.                                         return gotValue
  43.                                     else
  44.                                         xmlUnloadFile(xml)
  45.                                         outputDebugString("getXMLData - Could not get value/attribute '"..attribute.."'")
  46.                                         return false
  47.                                     end
  48.                                 end
  49.                             end
  50.                         end
  51.                     else
  52.                         xmlUnloadFile(xml)
  53.                         outputDebugString("getXMLData - Could not open specified file (parameter 1)")
  54.                         return false
  55.                     end
  56.                 else
  57.                     xmlUnloadFile(xml)
  58.                     outputDebugString("getXMLData - Could not split childs (parameter 2) string")
  59.                     return false
  60.                 end
  61.             else
  62.                 xmlUnloadFile(xml)
  63.                 outputDebugString("getXMLData - Specified file doesn't exist in resource foilder (parameter 1)")
  64.                 return false
  65.             end
  66.         else
  67.             xmlUnloadFile(xml)
  68.             outputDebugString("getXMLData - You must insert a 3rd parameter, the attribute you want get")
  69.             return false
  70.         end
  71.     else
  72.         xmlUnloadFile(xml)
  73.         outputDebugString("getXMLData - Invalid file parameter (parameter 1)")
  74.         return false
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement