XmlDestroyNode: Difference between revisions
		
		
		
		
		
		Jump to navigation
		Jump to search
		
				
		
		
	
No edit summary  | 
				|||
| Line 14: | Line 14: | ||
Returns ''true'' if the [[xml node]] was successfully destroyed, ''false'' otherwise.  | Returns ''true'' if the [[xml node]] was successfully destroyed, ''false'' otherwise.  | ||
==Example==  | ===Example===  | ||
<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'.  | |||
<syntaxhighlight lang="lua">  | <syntaxhighlight lang="lua">  | ||
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)  | |||
</syntaxhighlight>  | </syntaxhighlight>  | ||
</section>  | |||
==See Also==  | ==See Also==  | ||
{{XML functions}}  | {{XML functions}}  | ||
[[Category:Needs Example]]  | [[Category:Needs Example]]  | ||
Revision as of 18:06, 24 May 2012
This function destroys a XML node from the XML node tree.
Syntax
bool xmlDestroyNode ( xmlnode theXMLNode )
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 [-]
ServerThis 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)