Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getXMLData(file, type, childs, attribute)
- if file then
- if attribute then
- if fileExists(file) then
- childs = split(childs, string.byte(","))
- if #childs >= 1 then
- xml = xmlLoadFile(file)
- if xml then
- local currentChild = false
- for i, child in pairs(childs) do
- if i == #childs and currentChild ~= false then
- if type == "value" then
- gotValue = xmlNodeGetValue(currentChild)
- elseif type == "attribute" then
- gotValue = xmlNodeGetAttribute(currentChild, attribute)
- end
- if gotValue then
- xmlUnloadFile(xml)
- return gotValue
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Could not get value/attribute '"..attribute.."'")
- return false
- end
- else
- currChild = xmlFindChild(xml, child, 0)
- if currChild then
- currentChild = currChild
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Could not get child '"..child.."' ("..i..")")
- return false
- end
- if #childs == 1 then
- if type == "value" then
- gotValue = xmlNodeGetValue(currentChild)
- elseif type == "attribute" then
- gotValue = xmlNodeGetAttribute(currentChild, attribute)
- end
- if gotValue then
- xmlUnloadFile(xml)
- return gotValue
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Could not get value/attribute '"..attribute.."'")
- return false
- end
- end
- end
- end
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Could not open specified file (parameter 1)")
- return false
- end
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Could not split childs (parameter 2) string")
- return false
- end
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Specified file doesn't exist in resource foilder (parameter 1)")
- return false
- end
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - You must insert a 3rd parameter, the attribute you want get")
- return false
- end
- else
- xmlUnloadFile(xml)
- outputDebugString("getXMLData - Invalid file parameter (parameter 1)")
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement