- Documentation
- Shared functions
- xmlLoadFile
Function
xmlLoadFile
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 = falsetrue= 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
xmlUnloadFileFrees a document from memory. All its nodes become invalid. Unsaved changes are lost.xmlNodeGetChildrenWithout an index returns a table of all the node's children; with an index (from 0) - one child.xmlCreateFileCreates a new XML document with a root node of the given name. The document is in memory; it reaches the disk only afterxmlSaveFile. An existing file is overwritten on save.xmlLoadStringLoads an XML document directly from a string (e.g. received withfetchRemote), read-only. Returns the root node.