当前位置: 首页> 函数类别大全> children

children

返回指定节点的子节点。
名称:children
分类:未分类
所属语言:php
一句话介绍:返回指定节点的子节点。

定义和用法

children() 函数用于查找指定节点的子节点。

实例

例子 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>";
  }
?>

运行实例

语法

SimpleXMLElement::children(ns, prefix)
参数 描述
ns 可选。指定 XML 命名空间。
prefix

可选。布尔值。如果为 TRUE,ns 被视为前缀;如果为 FALSE,ns 被视为命名空间 URL。

默认为 FALSE。

同类函数
  • 为下一个 XPath 查询创建命名空间上下文。 registerXPathNamespace

    registerXPathNamespace

    为下一个XPath查询创建命名空间上下文
  • 返回元素的属性/值。 attributes

    attributes

    返回元素的属性/值。
  • 返回 MySQL 服务器主机名和连接类型。 get_host_info

    get_host_info

    返回MySQL服务器主机名和连接类型。
  • 从结果集中取得一行作为数字数组。 mysql_fetch_row

    mysql_fetch_row

    从结果集中取得一行作为数字数组。
  • 向服务器发送 SITE 命令。 ftp_site

    ftp_site

    向服务器发送SITE命令。
  • 返回 ZIP 文件中的一个项目的压缩方法。 zip_entry_compressionmethod

    zip_entry_compressionmethod

    返回ZIP文件中的一个项目的压缩方法。
  • 针对指定的年份和历法,返回一个月中的天数。 cal_days_in_month

    cal_days_in_month

    针对指定的年份和历法,返回一个月中的天数
  • 转义字符串中的特殊字符以用于 SQL 语句。 real_escape_string

    real_escape_string

    转义字符串中的特殊字符以用于SQL语句。
热门文章