xmlCreateFile | Multi Theft Auto: Wiki Skip to content

xmlCreateFile

Client-side
Server-side
Shared

This function creates a new XML document, which can later be saved to a file by using xmlSaveFile. This function will overwrite the file specified if it already exists.

To prevent memory leaks, ensure each call to xmlCreateFile has a matching call to xmlUnloadFile.

If you do not want to share the content of the created file with other servers, prepend the file path with @ (See Filepath for more information).

OOP Syntax Help! I don't understand this!

  • Constructor: XML(...)

Syntax

xmlnode|false xmlCreateFile ( string filePath, string rootNodeName )
Required Arguments
  • filePath: The Filepath of the file in the following format: ":resourceName/path". resourceName is the name of the resource the file will be in, and path is the path from the root directory of the resource to the file. For example, if you want to create a file named new.xml in the resource ctf, it can be created from another resource this way xmlCreateFile(":ctf/new.xml", "newroot"). If the file is in the current resource, only the file path is necessary, e.g. xmlCreateFile("new.xml", "newroot"). Note that if a different resource than default is being accessed, the caller resource needs access to general.ModifyOtherObjects in the ACL.
  • rootNodeName: The name of the root node in the XML document.

Returns

  • xmlnode|false: xmlnode

Returns the root xmlnode object of the new XML file if successful, or false otherwise.

Code Examples

client

This example allows a player to use the command createfile to create an .xml file.

-- Creates a file named "new.xml" with root node "newroot" and childnode "newchild".
function createFileHandler()
local RootNode = xmlCreateFile("new.xml"," newroot")
if (not RootNode) then
return
end
local NewNode = xmlCreateChild(RootNode, "newchild")
if (not NewNode) then
return
end
xmlSaveFile(RootNode)
xmlUnloadFile(RootNode)
end
addCommandHandler("createfile", createFileHandler)