Classes

Method XmlNode():getNodes() Foundation

Gets all or a subset of subnodes.

Syntax
:getNodes( [<bFilter>] ) --> aNodes
Parameters
<bFilter>
A codeblock representing a logical expression which is evaluated for each subnode. The codeblock receives as its first parameter the XmlNode() object for which the codeblock is evaluated. Only nodes for which the codeblock returns .T. (true) are added to the return array. If <bFilter> is not passed, all subnodes are added to the return array.
Return

An array of XmlNode() objects representing the subnodes assigned to the node object.

Description

The method :getNodes() collects all or a subset of subnodes assigned to a node object. By passing a codeblock in the optional <bFilter> parameter, a user-defined filter can be implemented so that :getNodes() returns only subnodes matching a certain criteria.

// In this example, a codeblock is used to implement a filter criteria for 
// XML nodes to be returned by the method XmlNode:getNodes() 
PROCEDURE Main 
LOCAL cXml 
LOCAL oRootNode 
LOCAL bFilter 
LOCAL aNodes 

TEXT INTO cXml WRAP 
<?xml version="1.0" encoding="UTF-8"?> 
<list> 
  <crew firstname="James" lastname="Kirk" rank="Captain" /> 
  <crew firstname="Nyota" lastname="Uhura" rank="Chief Communications Officer" /> 
  <crew firstname="Pavel" lastname="Chekov" rank="Navigator" /> 
 </list> 
ENDTEXT 

/* 
 * Query all nodes having "Uhura" assigned to the attribute "lastname" 
 */ 
oRootNode := XmlSimpleParser( cXml ) 
bFilter := { |oXmlNode| oXmlNode:LastName == "Uhura" } 
aNodes := oRootNode:getNodes( bFilter ) 

? aNodes[1]:toXML() // -> <crew firstname="Nyota" lastname="Uhura" rank="Chief Communications Officer"/> 

WAIT 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.