xmlFindChild
Client-side
Server-side
Shared
This function returns a named child node of an XML node.
OOP Syntax Help! I don't understand this!
- Method: xmlnode:findChild(...)
Syntax
xmlnode|false xmlFindChild ( xmlnode parentNode, string tagName, int index )
Required Arguments
- parentNode: This is an xmlnode that you want to find the child node under.
- tagName: This is the name of the child node you wish to find (case-sensitive).
- index: This is the 0-based 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
- xmlnode|false: xmlnode
Returns an xmlnode if the node was found, false otherwise.
Code Examples
shared
If you wanted to find an instructions node in an xml file like this:
<root version="2.0"> <options> <instructions>Start at the beginning and keep going until the end!</instructions> </options></root>
You could use the following code to print the text in the instructions node to the chatbox:
local rootNode = xmlLoadFile("test.xml")if (not rootNode) then returnend
local optionsNode = xmlFindChild(rootNode, "options", 0)if (optionsNode) then local instructionsNode = xmlFindChild(optionsNode, "instructions", 0)
if (instructionsNode) then local instructions = xmlNodeGetValue(instructionsNode) outputChatBox(instructions) endend
xmlUnloadFile(rootNode)