Method XmlNode():getNodes() Foundation
Gets all or a subset of subnodes.
:getNodes( [<bFilter>] ) --> aNodes
An array of XmlNode() objects representing the subnodes assigned to the node object.
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 TRIMMED
<?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
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.