XmlNodeSetAttribute: Difference between revisions
Jump to navigation
Jump to search
Black Dragon (talk | contribs) mNo edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
{{Server client function}} | |||
This function is used to edit an attribute of a node in a configuration file. | This function is used to edit an attribute of a node in a configuration file. | ||
Line 15: | Line 16: | ||
Returns ''true'' if edit was successful, ''false'' if the node and/or attribute do not exist, or if they're faulty. | Returns ''true'' if edit was successful, ''false'' if the node and/or attribute do not exist, or if they're faulty. | ||
==Example== | ==Example== | ||
In a gamemode, we want a command to change the marker color in the configuration file. | |||
config.xml: | |||
<syntaxhighlight lang="xml"> | |||
<config> | |||
<markers color="255,100,0" /> | |||
</config> | |||
</syntaxhighlight> | |||
Lua code: | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
config = xmlLoadFile("config.xml") | |||
function changeConfigMarkerColor(player, command, r, g, b) | |||
markernode = xmlFindSubNode(config, "markers", 0) | |||
xmlNodeSetAttribute(markernode, "color", r .. "," .. g .. "," .. b) | |||
end | |||
addCommandHandler("markercolor", changeConfigMarkerColor) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Note that this example only changes the in-memory XML document. If you want to save the changed document back to the hard drive, use [[xmlSaveFile]]. | |||
==See Also== | ==See Also== |
Revision as of 16:39, 15 August 2007
This function is used to edit an attribute of a node in a configuration file.
Syntax
bool xmlNodeSetAttribute ( xmlnode xmlnode, string name, var value )
Required Arguments
- xmlnode: The node in which you wish to edit the attribute.
- name: The name of the attribute.
- value: The value which you wish to change the attribute to.
Returns
Returns true if edit was successful, false if the node and/or attribute do not exist, or if they're faulty.
Example
In a gamemode, we want a command to change the marker color in the configuration file.
config.xml:
<config> <markers color="255,100,0" /> </config>
Lua code:
config = xmlLoadFile("config.xml") function changeConfigMarkerColor(player, command, r, g, b) markernode = xmlFindSubNode(config, "markers", 0) xmlNodeSetAttribute(markernode, "color", r .. "," .. g .. "," .. b) end addCommandHandler("markercolor", changeConfigMarkerColor)
Note that this example only changes the in-memory XML document. If you want to save the changed document back to the hard drive, use xmlSaveFile.