Current Location: Home> Function Categories> children

children

Returns the child node of the specified node.
Name:children
Category:Uncategorized
Programming Language:php
One-line Description:Returns the child node of the specified node.

Definition and usage

children() function is used to find children of a specified node.

实例

例子 1

查找 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>";
  }
?>

运行实例

例子 2

查找 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>";
  }
?>

运行实例

grammar

 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.

Similar Functions
Popular Articles