XmlDestroyNode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(add oop syntax)
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
tba
This function destroys a XML node from the XML node tree.


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool xmlDestroyNode ( xmlnode )
bool xmlDestroyNode ( xmlnode theXMLNode )
</syntaxhighlight>  
</syntaxhighlight>  
{{OOP||[[xmlnode]]:destroy}}


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''theXMLNode:''' The [[xml node]] you want to destroy.
*'''argumentName:''' description


<!-- Only include this section below if there are optional arguments -->
===Returns===
===Optional Arguments===  
Returns ''true'' if the [[xml node]] was successfully destroyed, ''false'' otherwise.
{{OptionalArg}}
*'''argumentName2:''' description
*'''argumentName3:''' description


===Returns===
===Example===
Returns a table of resources.
<section name="Server" class="server" show="true">
This example will add a command called '/delnode' and it will create an xml file called 'test.xml'.


==Example==
This function lists all loaded resources in the console.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function blabla ()
addEventHandler("onResourceStart", resourceRoot, function()
    --this does blabla
    xml = xmlLoadFile("test.xml")
end
    if not xml then
        xml = xmlCreateFile("test.xml", "root")
        xmlCreateChild(xml, "node")
        xmlSaveFile(xml)
    end
end)
 
addCommandHandler("delnode", function(player)
    local node = xmlFindChild(xml, "node", 0)
    if not node then xmlUnloadFile(xml) return end
    xmlDestroyNode(node)
    xmlSaveFile(xml)
    xmlUnloadFile(xml)
    outputChatBox("You destroyed the node!", player, 0, 255, 0, false)
end)
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{XML_functions}}
{{XML functions}}
[[Category:Needs Example]]
[[ru:xmlDestroyNode]]

Latest revision as of 20:13, 2 January 2015

This function destroys a XML node from the XML node tree.

Syntax

bool xmlDestroyNode ( xmlnode theXMLNode )

OOP Syntax Help! I don't understand this!

Method: xmlnode:destroy(...)


Required Arguments

  • theXMLNode: The xml node you want to destroy.

Returns

Returns true if the xml node was successfully destroyed, false otherwise.

Example

Click to collapse [-]
Server

This example will add a command called '/delnode' and it will create an xml file called 'test.xml'.

addEventHandler("onResourceStart", resourceRoot, function()
    xml = xmlLoadFile("test.xml")
    if not xml then
        xml = xmlCreateFile("test.xml", "root")
        xmlCreateChild(xml, "node")
        xmlSaveFile(xml)
    end
end)

addCommandHandler("delnode", function(player)
    local node = xmlFindChild(xml, "node", 0)
    if not node then xmlUnloadFile(xml) return end
    xmlDestroyNode(node)
    xmlSaveFile(xml)
    xmlUnloadFile(xml)
    outputChatBox("You destroyed the node!", player, 0, 255, 0, false)
end)

See Also