XmlNodeSetValue

From Multi Theft Auto: Wiki
Revision as of 14:06, 26 March 2009 by Awwu (talk | contribs)
Jump to navigation Jump to search

This function is made to be able to assign values to tags in XML files (eg. <something>anything</something>).

Syntax

bool xmlNodeSetValue ( xmlnode theXMLNode, string value )            

Required Arguments

  • theXMLNode: The xml node you want to set the value of.
  • value: The string value you want the node to have.

Returns

Returns true if value was successfully set, false otherwise.

Example

In this example a sample value is inserted into a XML file.

local xmlFile = xmlLoadFile ( "exampleFile.xml" ) -- Open a file already created
if xmlFile then -- If it's indeed opened
    local node = xmlCreateSubNode ( xmlFile, "somesubnode" ) -- Create a new subnode
    local success = xmlNodeSetValue ( node, "somevalue" ) -- Set the value of it
    if success then -- Check if it was successful
        xmlSaveFile ( xmlFile ) -- Save the file
    end
end

After both changing the value and saving the XML file with xmlSaveFile, the file will look like this:

Click to collapse [-]
exampleFile.xml
<somenode>
	<somesubnode>somevalue</somesubnode>
</somenode>

See Also