找到注释节点的子节点:
<?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:添加了可选的字首范围 |
找到 body 节点的子节点:
<?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>";
}
?>
运行示例 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!