xmlNodeGetAttributes | Multi Theft Auto: Wiki Skip to content

xmlNodeGetAttributes

Client-side
Server-side
Shared

Returns all the attributes of a specific XML node.

OOP Syntax Help! I don't understand this!

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

Syntax

table|false xmlNodeGetAttributes ( xmlnode node )
Required Arguments
  • node: The xmlnode to get the attributes of.

Returns

  • table|false: attributes

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.

Code Examples

shared

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

If the meta.xml looked like this: meta.xml

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

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

type = gamemode
name = My gamemode
author = me

Code

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)