ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Shared functions
  3. xmlLoadFile

Function

xmlLoadFile

Server and clientXMLIdentical to MTA:SA

Loads an XML file and returns its root node, from which you can read children and attributes. On the server the path is relative to the resource folder (you cannot leave it). On the client it reads the script's own files and then <file> files sent by the server; a ":other/file.xml" path points to another resource's file. Remember xmlUnloadFile when the document is no longer needed.

Syntax

xmlnode xmlLoadFile(string filePath [, bool readOnly = false])

Arguments

filePathstring
Path to the file.
readOnlybool, optional = false
true = read only (saving rejected).

Returns

The root node, or false when the file is missing or broken.

Example

local root = xmlLoadFile("spawns.xml", true)
if root then
    for _, node in ipairs(xmlNodeGetChildren(root)) do
        local x = tonumber(xmlNodeGetAttribute(node, "x"))
        local y = tonumber(xmlNodeGetAttribute(node, "y"))
        local z = tonumber(xmlNodeGetAttribute(node, "z"))
        createPickup(x, y, z, 0, 100)
    end
    xmlUnloadFile(root)
end

See also