XmlNodeGetAttribute: 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 return an attribute of a node in a configuration file. | This function is used to return an attribute of a node in a configuration file. | ||
Line 15: | Line 16: | ||
==Example== | ==Example== | ||
Suppose we have a gametype where only one type of car is used, and this type should not depend on the map but rather be set in an external configuration file and be used in all maps. Here's an example where the configuration file is an XML document: | |||
settings.xml | |||
<syntaxhighlight lang="xml"> | |||
<car model="528" /> | |||
</syntaxhighlight> | |||
Lua code | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | xml = xmlLoadFile("settings.xml") -- load XML file and get its root element | ||
carmodel = xmlNodeGetAttribute(xml, "model") -- get attribute of root element | |||
... | |||
function createCar(x, y, z) | |||
createVehicle(carmodel, x, y, z) | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 16:24, 15 August 2007
This function is used to return an attribute of a node in a configuration file.
Syntax
string xmlNodeGetAttribute ( xmlnode xmlnode, string name )
Required Arguments
- xmlnode: The node from which you wish to return the attribute
- name: The name of the attribute.
Returns
Returns the attribute in string form.
Example
Suppose we have a gametype where only one type of car is used, and this type should not depend on the map but rather be set in an external configuration file and be used in all maps. Here's an example where the configuration file is an XML document:
settings.xml
<car model="528" />
Lua code
xml = xmlLoadFile("settings.xml") -- load XML file and get its root element carmodel = xmlNodeGetAttribute(xml, "model") -- get attribute of root element ... function createCar(x, y, z) createVehicle(carmodel, x, y, z) end