PHPのchildren()関数
例
ノートノードの子を検索します。
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child)
{
echo "Child node: " . $child . "<br>";
}
?>
定義と使用法
children()関数は、指定されたノードの子を検索します。
構文
SimpleXMLElement::children(ns, prefix)
パラメータ値
Parameter | Description |
---|---|
ns | Optional. Specifies an XML namespace |
prefix | Optional. A Boolean value. If TRUE ns is regarded as a prefix. If FALSE ns is regarded as a namespace URL. Default is FALSE |
技術的な詳細
戻り値: | SimpleXMLElementオブジェクトを返します |
---|---|
PHPバージョン: | 5.0以降 |
PHP変更ログ: | PHP 5.2:オプションのプレフィックスパラメータを追加しました |
その他の例
例
ボディノードの子を検索します。
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</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>";
}
?>
❮PHPSimpleXMLリファレンス