The [xml_node->childNodes] method returns an xml_nodeList of all of the immediate children of the named xml_node.
Note: the items of the resulting list are indexed starting at 0.
xml_node->childNodes
This example uses the [xml->childNodes] method to drill down into the first child node of the XML node "month" to retrieve the node containing the last day of the month. Notice the indexing that is used in the [xml_nodeList->item] method to retrieve the desired xml_element.
Code
var(aMonth = xml('<month>
<data>
<name>March</name>
<date type="lastDay">31</date>
</data>
<date>4</date>
<date>11</date>
<date>16</date>
<date>23</date>
<date>30</date>
</month>') )
'The child nodes are: \n'+$aMonth->childNodes()+'\n\n'
var( theMonth = $aMonth->childNodes->item(0) )
'The Month is: \n'+$theMonth+'\n\n'
var( lastDay = $theMonth->childNodes->item(1) )
'The lastDay is '+$lastDay
Result
The child nodes are: xml_nodeList(<data> <name>March</name> <date type="lastDay">31</date> </data>, <date>4</date>, <date>11</date>, <date>16</date>, <date>23</date>, <date>30</date>) The Month is: <data> <name>March</name> <date type="lastDay">31</date> </data> The lastDay is <date type="lastDay">31</date>
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Recent Comments