XmlCreateChild: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(7 intermediate revisions by 7 users not shown)
Line 5: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">xmlnode xmlCreateChild ( xmlnode parentNode, string tagName )</syntaxhighlight>
<syntaxhighlight lang="lua">xmlnode xmlCreateChild ( xmlnode parentNode, string tagName )</syntaxhighlight>
 
{{OOP||[[xmlnode]]:createChild}}
===Required Arguments===  
===Required Arguments===  
*'''parentNode:''' the [[xmlnode]] you want to create a new child node under.
*'''parentNode:''' the [[xmlnode]] you want to create a new child node under.
Line 14: Line 14:


==Example==
==Example==
[[Category:Needs Example]]
This example allows a player to use the command 'createfile' to create an .xml file.
<syntaxhighlight lang="lua">
-- 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)
</syntaxhighlight>


==See Also==
==See Also==
{{XML functions}}
{{XML functions}}
[[Category:Needs Example]]
[[ru:xmlCreateChild]]
[[pt-br:XmlCreateChild]]

Latest revision as of 04:26, 20 February 2022

This function creates a new child node under an XML node.

Syntax

xmlnode xmlCreateChild ( xmlnode parentNode, string tagName )

OOP Syntax Help! I don't understand this!

Method: xmlnode:createChild(...)


Required Arguments

  • parentNode: the xmlnode you want to create a new child node under.
  • tagName: the type of the child node that will be created.

Returns

Returns the created xmlnode if successful, false otherwise.

Example

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