XmlFindSubNode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 6: Line 6:
<syntaxhighlight lang="lua">xmlnode xmlFindSubNode ( xmlnode parent, string subnode, int index )</syntaxhighlight>
<syntaxhighlight lang="lua">xmlnode xmlFindSubNode ( xmlnode parent, string subnode, int index )</syntaxhighlight>


===Required Arguments===
===Required Arguments===  
* '''parent''': This is an [[xmlnode]] that you want to find the subnode under. This could be a node returned from another call to [[xmlFindSubNode]].
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
* '''subnode''': This is the name of the subnode you wish to find.
*'''argumentName:''' description
* '''index''': This is the index of the node you wish to find. For example, to find the 5th subnode with a particular name, you would use 4 as the index value. To find the first occurence, use 0.
 
<!-- Only include this section below if there are optional arguments -->
===Optional Arguments===
{{OptionalArg}}
*'''argumentName2:''' description
*'''argumentName3:''' description


===Returns===
===Returns===
Returns an [[xmlnode]] object if the node was found, ''false'' otherwise.
Returns a table of resources.


==Example==
==Example==
<section name="Server" class="server" show="true">
This function lists all loaded resources in the console.
If you wanted to find the 'instructions' node in a map file like this:
<syntaxhighlight lang="xml">
<map version="2.0">
      <options>
            <instructions>Start at the begining and keep going until the end!</instructions>
      </options>
</map>
</syntaxhighlight>
 
You could use the following code:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
maproot = getLoadedMapXMLRoot ();
function blabla ()
optionsnode = xmlFindSubNode ( maproot, "options", 0 );
    --this does blabla
instructionsnode = xmlFindSubNode ( optionsnode, "instructions", 0 );
end
</syntaxhighlight>
</syntaxhighlight>


Note: You could use [[getMapOption]] to do the same thing.
</section>


==See Also==
==See Also==
{{XML functions}}
{{XML functions}}

Revision as of 16:48, 19 October 2007

This function returns a named sub node of a particular XML node.

Syntax

xmlnode xmlFindSubNode ( xmlnode parent, string subnode, int index )

Required Arguments

  • argumentName: description

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • argumentName2: description
  • argumentName3: description

Returns

Returns a table of resources.

Example

This function lists all loaded resources in the console.

function blabla ()
     --this does blabla
end


See Also