children
Returns the child node of the specified node.
children()
function is used to find children of a specified node.
查找 note 节点的子节点:
<?php $note=<<<XML <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Do not forget the meeting!</body> </note> XML; $xml=simplexml_load_string($note); foreach ($xml->children() as $child) { echo "Child node: " . $child . "<br>"; } ?>
运行实例
查找 body 节点的子节点:
<?php $note=<<<XML <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body><span>Important!</span> Do not forget me this weekend!</body> </note> XML; $xml=simplexml_load_string($note); foreach ($xml->body[0]->children() as $child) { echo "Child node: " . $child . "<br>"; } ?>
运行实例
SimpleXMLElement :: children ( ns , prefix )
parameter | describe |
---|---|
ns | Optional. Specifies the XML namespace. |
prefix |
Optional. Boolean value. If TRUE, ns is considered as a prefix; if FALSE, ns is considered as a namespace URL. The default is FALSE. |