XmlNodeGetAttribute: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Fix oop syntax)
 
(11 intermediate revisions by 10 users not shown)
Line 1: Line 1:
[[Category:Incomplete]]
__NOTOC__
 
{{Server client function}}
__NOTOC__
This function is used to return an attribute of a node in a configuration file.
This fake function is for use with blah & blah and does blahblahblabhalbhl


==Syntax==  
==Syntax==  
<syntaxhighlight lang="xml">
<syntaxhighlight lang="lua">
string xmlNodeGetAttribute ( xmlnode xmlnode, string name )             
string xmlNodeGetAttribute ( xmlnode node, string name )             
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[xmlnode]]:getAttribute||xmlNodeSetAttribute}}
===Required Arguments===  
===Required Arguments===  
*'''argumentName:''' description
*'''node:''' The node from which you wish to return the attribute
 
*'''name:''' The name of the attribute.
===Optional Arguments===
{{OptionalArg}}
*'''argumentName2:''' descriptiona
*'''argumentName3:''' description


===Returns===
===Returns===
Returns ''true'' if blah, ''false'' otherwise.
Returns the attribute in string form or ''false'', if the attribute is not defined.


==Example==  
==Example==  
This example does...
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">
<syntaxhighlight lang="xml">
--This line does...
<car model="528" posX="123.4" posY="456.7" posZ="12.3" rot="90.0" />
blabhalbalhb --abababa
</syntaxhighlight>
--This line does this...
 
mooo
Lua code
<syntaxhighlight lang="lua">
local xml = getResourceConfig("settings.xml")      -- load XML file and get its root element
local carmodel = xmlNodeGetAttribute(xml, "model")    -- get attribute of root element
local carX = xmlNodeGetAttribute(xml, "posX")
local carY = xmlNodeGetAttribute(xml, "posY")
local carZ = xmlNodeGetAttribute(xml, "posZ")
local carA = xmlNodeGetAttribute(xml, "rot")
createVehicle(carmodel, tonumber(carX), tonumber(carY), tonumber(carZ), 0.0, 0.0, tonumber(carA))
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{FunctionArea_Functions}}
{{XML_functions}}
{{XML_functions}}
[[ru:xmlNodeGetAttribute]]

Latest revision as of 14:50, 6 August 2016

This function is used to return an attribute of a node in a configuration file.

Syntax

string xmlNodeGetAttribute ( xmlnode node, string name )             

OOP Syntax Help! I don't understand this!

Method: xmlnode:getAttribute(...)
Counterpart: xmlNodeSetAttribute


Required Arguments

  • node: The node from which you wish to return the attribute
  • name: The name of the attribute.

Returns

Returns the attribute in string form or false, if the attribute is not defined.

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" posX="123.4" posY="456.7" posZ="12.3" rot="90.0" />

Lua code

local xml = getResourceConfig("settings.xml")      -- load XML file and get its root element
local carmodel = xmlNodeGetAttribute(xml, "model")    -- get attribute of root element
local carX = xmlNodeGetAttribute(xml, "posX")
local carY = xmlNodeGetAttribute(xml, "posY")
local carZ = xmlNodeGetAttribute(xml, "posZ")
local carA = xmlNodeGetAttribute(xml, "rot")
createVehicle(carmodel, tonumber(carX), tonumber(carY), tonumber(carZ), 0.0, 0.0, tonumber(carA))

See Also