XmlNodeGetAttributes: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(One intermediate revision by one other user not shown)
Line 8: Line 8:
table xmlNodeGetAttributes ( xmlnode node )
table xmlNodeGetAttributes ( xmlnode node )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[xmlnode]]:getAttributes|attributes}}
===Required Arguments===
===Required Arguments===
*'''node:''' the XML node to get the attributes of.
*'''node:''' the XML node to get the attributes of.
Line 48: Line 48:
==See Also==
==See Also==
{{XML functions}}
{{XML functions}}
[[ru:xmlNodeGetAttributes]]

Latest revision as of 21:27, 20 December 2015

Returns all the attributes of a specific XML node.

Syntax

table xmlNodeGetAttributes ( xmlnode node )

OOP Syntax Help! I don't understand this!

Method: xmlnode:getAttributes(...)
Variable: .attributes


Required Arguments

  • node: the XML node to get the attributes of.

Returns

If successful, returns a table with as keys the names of the attributes and as values the corresponding attribute values. If the node has no attributes, returns an empty table. In case of failure, returns false.

Example

Click to collapse [-]
Server

This example code opens the meta.xml of the resource it belongs to, and prints all attributes of the <info> node to the console.

local meta = xmlLoadFile ( "meta.xml" )
local info = xmlFindChild ( meta, "info", 0 )
if info then
    local attrs = xmlNodeGetAttributes ( info )
    for name,value in pairs ( attrs ) do
        outputConsole ( name .. " = " .. value )
    end
end
xmlUnloadFile ( meta )

If the meta.xml looked like this:

<meta>
    <info type="gamemode" name="My gamemode" author="me"/>
    ...
</meta>

Then the above code would output (not necessarily in this order):

type = gamemode
name = My gamemode
author = me

See Also