PHP children() 函數
定義和用法
children() 函數獲取指定節(jié)點的子節(jié)點。
語法
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!