【发布时间】:2018-07-22 09:42:40
【问题描述】:
我如何从下面的 xml 标记中获取 a b c d e...
<api:field name="test">
<api:text>a</api:text>
<api:text>b</api:text>
<api:text>c</api:text>
<api:text>d</api:text>
<api:text>e</api:text>
</api:field>
我正在尝试使用这个 for 循环:
foreach ($xml->xpath('//api:field[@name="test"]') as $item)
{
foreach ($item->children() as $child) {
...
}
}
但我不知道如何访问不包含属性的子节点。
我需要专门获取父节点“test”的子值,所以请不要给我 $xml->xpath("//api:text"); 作为答案.这个答案的问题是我们可能会在其他父节点下看到 ,而我只想从特定的父节点获取子值。在这种情况下 name="test"。
【问题讨论】:
标签: php xml namespaces