XmlNodeGetAttributes: Difference between revisions
Jump to navigation
Jump to search
(New page: __NOTOC__ {{Server client function}} Returns all the attributes of a specific XML node. ==Syntax== <syntaxhighlight lang="lua"> table xmlNodeGetAttributes ( xmlnode node ) </syntaxhighlight> ===Required Arguments=...) |
mNo edit summary |
||
Line 20: | Line 20: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
local meta = xmlLoadFile ( "meta.xml" ) | local meta = xmlLoadFile ( "meta.xml" ) | ||
local info = xmlFindChild ( meta, "info", 0) | local info = xmlFindChild ( meta, "info", 0 ) | ||
if info then | if info then | ||
local attrs = xmlNodeGetAttributes ( info ) | local attrs = xmlNodeGetAttributes ( info ) | ||
for name,value in pairs(attrs) do | for name,value in pairs ( attrs ) do | ||
outputConsole ( name .. " = " .. value ) | outputConsole ( name .. " = " .. value ) | ||
end | end |
Revision as of 16:27, 25 May 2008
Returns all the attributes of a specific XML node.
Syntax
table xmlNodeGetAttributes ( xmlnode node )
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 [-]
ServerThis 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
- xmlCopyFile
- xmlCreateChild
- xmlCreateFile
- xmlDestroyNode
- xmlFindChild
- xmlLoadFile
- xmlLoadString
- xmlNodeGetAttribute
- xmlNodeGetAttributes
- xmlNodeGetChildren
- xmlNodeGetName
- xmlNodeGetParent
- xmlNodeGetValue
- xmlNodeSetAttribute
- xmlNodeSetName
- xmlNodeSetValue
- xmlSaveFile
- xmlUnloadFile