XmlNodeSetValue: Difference between revisions
Jump to navigation
Jump to search
Paul Cortez (talk | contribs) No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{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. | |||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
bool xmlNodeSetValue ( xmlnode | bool xmlNodeSetValue ( xmlnode theXMLNode, string value ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*''' | *'''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. | ||
===Returns=== | ===Returns=== | ||
Returns ''true'' if | Returns ''true'' if value was successfully set, ''false'' otherwise. | ||
==Example== | ==Example== | ||
In this example is | In this example a sample value is inserted into a XML file. | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local xmlFile=xmlLoadFile(" | 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 success = xmlNodeSetValue ( node, "somevalue" ) -- Set the value of it | |||
if success then -- Check if it was successful | |||
xmlSaveFile ( xmlFile ) -- Save the file | |||
end | |||
end | end | ||
</syntaxhighlight> | </syntaxhighlight> | ||
After both changing the value and saving the XML file with [[xmlSaveFile]], the file will look like this: | |||
<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== | ||
{{ | {{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
- xmlCopyFile
- xmlCreateChild
- xmlCreateFile
- xmlDestroyNode
- xmlFindChild
- xmlLoadFile
- xmlLoadString
- xmlNodeGetAttribute
- xmlNodeGetAttributes
- xmlNodeGetChildren
- xmlNodeGetName
- xmlNodeGetParent
- xmlNodeGetValue
- xmlNodeSetAttribute
- xmlNodeSetName
- xmlNodeSetValue
- xmlSaveFile
- xmlUnloadFile