XmlSaveFile: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Prevented memory leak)
 
(5 intermediate revisions by 4 users not shown)
Line 5: Line 5:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">bool xmlSaveFile ( xmlnode rootNode ) </syntaxhighlight>
<syntaxhighlight lang="lua">bool xmlSaveFile ( xmlnode rootNode ) </syntaxhighlight>
 
{{OOP||[[xmlnode]]:saveFile}}
===Required Arguments===  
===Required Arguments===  
*'''rootNode:''' the root [[xmlnode]] of the loaded XML file.
*'''rootNode:''' the root [[xmlnode]] of the loaded XML file.
Line 13: Line 13:


==Example==
==Example==
This example loads an XML file then saves it again. The file should contain the same data, though it is possible that the order of the tags and/or the order of the attributes may have changed.
<syntaxhighlight lang="lua">
node = xmlLoadFile ( "test.xml" ) --load an xml file
xmlSaveFile( node ) --Save the xml file
</syntaxhighlight>
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
This example allows a player to use the command 'createfile' to create an .xml file.
This example allows a player to use the command 'createfile' to create an .xml file.
Line 27: Line 21:
local NewNode = xmlCreateChild(RootNode, "newchild")
local NewNode = xmlCreateChild(RootNode, "newchild")
xmlSaveFile(RootNode)
xmlSaveFile(RootNode)
xmlUnloadFile(RootNode)
end
end


Line 35: Line 30:
==See Also==
==See Also==
{{XML_functions}}
{{XML_functions}}
[[ru:xmlSaveFile]]

Latest revision as of 20:46, 12 May 2019

This function saves a loaded XML file.

Syntax

bool xmlSaveFile ( xmlnode rootNode ) 

OOP Syntax Help! I don't understand this!

Method: xmlnode:saveFile(...)


Required Arguments

  • rootNode: the root xmlnode of the loaded XML file.

Returns

Returns true if save was successful, false if the XML file does not exist.

Example

Click to collapse [-]
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")
local NewNode = xmlCreateChild(RootNode, "newchild")
xmlSaveFile(RootNode)
xmlUnloadFile(RootNode)
end

addCommandHandler("createfile", createFileHandler)

See Also