XmlNodeSetValue: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
[[Category:Incomplete]]
{{Server client function}}
 
__NOTOC__
__NOTOC__  
This function is made to be able to assign values to tags in XML files (eg. <something>anything</something>).
This function is made to be able to assign values in XML files. (for example <something>anything</something>)


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool xmlNodeSetValue ( xmlnode xmlnode, string value )             
bool xmlNodeSetValue ( xmlnode theXMLNode, string value )             
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===  
*'''xmlnode:''' The node you want to set the value of.
*'''theXMLNode:''' The [[xml node]] you want to set the value of.
*'''value:''' The value you want the node to have.
*'''value:''' The [[string]] value you want the node to have.
 
===Optional Arguments===
{{OptionalArg}}
*'''none'''


===Returns===
===Returns===
Returns ''true'' if successful, false otherwise.
Returns ''true'' if value was successfully set, ''false'' otherwise.


==Example==  
==Example==  
In this example is shown what xmlNodeSetValue does and how it works:
In this example a sample value is inserted into a XML file.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local xmlFile=xmlLoadFile("xmlfile.xml") --Open a file already created
local xmlFile = xmlLoadFile ( "exampleFile.xml" ) -- Open a file already created
if xmlFile then --If it's indeed opened:
if xmlFile then -- If it's indeed opened
local node=xmlCreateSubNode(xmlFile,"somesubnode") --Create a new subnode
    local node = xmlCreateSubNode ( xmlFile, "somesubnode" ) -- Create a new subnode
local success=xmlNodeSetValue(node,"somevalue") --Set the value of it
    local success = xmlNodeSetValue ( node, "somevalue" ) -- Set the value of it
if success then --Check if it was successful
    if success then -- Check if it was successful
xmlSaveFile(xmlFile) --Save the file
        xmlSaveFile ( xmlFile ) -- Save the file
end --End what still needs to be ended
    end
end
end
end
</syntaxhighlight>
</syntaxhighlight>
 
After both changing the value and saving the XML file with [[xmlSaveFile]], the file will look like this:
The xml file wil look like:
<section name="exampleFile.xml" class="server" show="true">
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
<somenode>
<somenode>
Line 40: Line 34:
</somenode>
</somenode>
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{FunctionArea_Functions}}
{{XML functions}}
{{XML_functions}}

Revision as of 14:06, 26 March 2009

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