XmlNodeGetChildren: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 4: Line 4:


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">xmlnode/table xmlNodeGetSubNodes( xmlnode parent, [ int index ])</syntaxhighlight>
<syntaxhighlight lang="lua">xmlnode/table xmlNodeGetChildren( xmlnode parent, [ int index ])</syntaxhighlight>


===Required Arguments===
===Required Arguments===
* '''parent''': This is an [[xmlnode]] that you want to find the sub nodes under.  
* '''parent''': This is an [[xmlnode]] that you want to find the children under.  


===Optional Arguments===  
===Optional Arguments===  
{{OptionalArg}}  
{{OptionalArg}}  
* '''index''': This is the index of the node you wish to find. For example, to find the 5th subnode, you would use 4 as the index value. To find the first occurence, use 0. If this is not set, it will return a list of all sub nodes.
* '''index''': This is the index of the node you wish to find. For example, to find the 5th subnode, you would use 4 as the index value. To find the first occurence, use 0. If this is not set, it will return a list of all children.


===Returns===
===Returns===
If index isn't specified, it returns a list of all sub nodes. Returns an [[xmlnode]] object if index was set and a node was found, otherwise it returns false.
If index isn't specified, it returns a list of all children. Returns an [[xmlnode]] object if index was set and a node was found, otherwise it returns false.


==Example==
==Example==
Line 30: Line 30:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
maproot = getLoadedMapXMLRoot ();
maproot = getLoadedMapXMLRoot ();
optionsnode = xmlNodeGetSubNodes( maproot, 0 ); -- In this case it would find the options sub node as the first under the 'map' node
optionsnode = xmlNodeGetChildren( maproot, 0 ); -- In this case it would find the options sub node as the first under the 'map' node
</syntaxhighlight>
</syntaxhighlight>



Revision as of 11:11, 6 April 2008

This function returns a single sub node or a list of sub nodes of a particular XML node.

Syntax

xmlnode/table xmlNodeGetChildren( xmlnode parent, [ int index ])

Required Arguments

  • parent: This is an xmlnode that you want to find the children under.

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.

  • index: This is the index of the node you wish to find. For example, to find the 5th subnode, you would use 4 as the index value. To find the first occurence, use 0. If this is not set, it will return a list of all children.

Returns

If index isn't specified, it returns a list of all children. Returns an xmlnode object if index was set and a node was found, otherwise it returns false.

Example

Click to collapse [-]
Server

If you wanted to find the 'instructions' node in a map file like this:

<map version="2.0">
      <options>
            <instructions>Start at the begining and keep going until the end!</instructions>
      </options>
</map>

You could use the following code:

maproot = getLoadedMapXMLRoot ();
optionsnode = xmlNodeGetChildren( maproot, 0 ); -- In this case it would find the options sub node as the first under the 'map' node

See Also