PHP children() ファンクション

定義と使用方法

children() ファンクションは指定されたノードのサブノードを取得します。

文法

class SimpleXMLElement
{
string children(ns,is_prefix)
}
引数 説明
ns オプションです。
is_prefix オプションです。デフォルトは false です。

XML ファイル:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

PHP コード:

<?php
$xml = simplexml_load_file("test.xml");
foreach ($xml->children() as $child)
  {
  echo "Child node: " . $child;
  }
?>

出力例:

Child node: George
Child node: John
Child node: Reminder
Child node: Don't forget the meeting!