XmlFindSubNode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Changed "DeprecatedWithAlt" template to "Deprecated")
 
(16 intermediate revisions by 9 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
{{Server client function}}
{{Deprecated|xmlFindChild}}
 
This function returns a named sub node of a particular XML node.
This function returns a named sub node of a particular XML node.


Line 7: Line 9:


===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]].
* '''parent''': This is an [[xmlnode]] that you want to find the subnode under. This could be a node returned from another call to [[xmlFindSubNode]].
* '''subnode''': This is the name of the subnode you wish to find.
* '''subnode''': This is the name of the subnode you wish to find.
* '''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.
* '''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.
===Returns===
Returns an [[xmlnode]] object if the node was found, ''false'' otherwise.


==Example==
==Example==
<section name="Server" class="server" show="true">
If you wanted to find the 'instructions' node in a map file like this:
If you wanted to find the 'instructions' node in a map file like this:
<syntaxhighlight lang="xml">
<syntaxhighlight lang="xml">
Line 18: Line 23:
       <options>
       <options>
             <instructions>Start at the begining and keep going until the end!</instructions>
             <instructions>Start at the begining and keep going until the end!</instructions>
       <options>
       </options>
</map>
</map>
</syntaxhighlight>
</syntaxhighlight>
Line 24: Line 29:
You could use the following code:
You could use the following code:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
maproot = [[getLoadedMapXMLRoot]] ();
maproot = getLoadedMapXMLRoot ()
optionsnode = [[xmlFindSubNode]] ( maproot, "options", 0 );
optionsnode = xmlFindSubNode ( maproot, "options", 0 )
instructionsnode = [[xmlFindSubNode]] ( optionsnode, "instructions", 0 );
instructionsnode = xmlFindSubNode ( optionsnode, "instructions", 0 )
</syntaxhighlight>
</syntaxhighlight>
</section>
==See Also==
{{XML functions}}

Latest revision as of 16:14, 13 February 2015

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use xmlFindChild instead.


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

Syntax

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

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.
  • subnode: This is the name of the subnode you wish to find.
  • 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.

Returns

Returns an xmlnode object if the node was found, false otherwise.

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 = xmlFindSubNode ( maproot, "options", 0 )
instructionsnode = xmlFindSubNode ( optionsnode, "instructions", 0 )

See Also