PHP children() 函数

定义和用法

children() 函数获取指定节点的子节点。

语法
  1. class SimpleXMLElement
  2. {
  3. string children(ns,is_prefix)
  4. }
参数描述
ns可选。
is_prefix可选。默认是 false。

例子

XML 文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <note>
  3. <to>George</to>
  4. <from>John</from>
  5. <heading>Reminder</heading>
  6. <body>Don't forget the meeting!</body>
  7. </note>

PHP 代码:

  1. <?php
  2. $xml = simplexml_load_file("test.xml");
  3. foreach ($xml->children() as $child)
  4. {
  5. echo "Child node: " . $child;
  6. }
  7. ?>

输出类似:

  1. Child node: George
  2. Child node: John
  3. Child node: Reminder
  4. Child node: Don't forget the meeting!

分类导航