我有这个xml对象,我想得到每个“p”$ xml-> query-> search [“p”] [0] - >属性[“title”],如何得到每个一个使用foreach?
SimpleXMLElement Object
(
[query] => SimpleXMLElement Object
(
[search] => SimpleXMLElement Object
(
[p] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ns] => 0
[title] => Amebiasis
[timestamp] => 2013-09-16T16:11:24Z
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ns] => 0
[title] => Entamoeba histolytica
[timestamp] => 2013-09-10T19:59:49Z
)
)
)
)
)
)
答案 0 :(得分:1)
你可以像这样使用xpath
$titles = $o->xpath('query/search/p/@title');
或者获取文档中的所有标题属性
$titles = $o->xpath('//@title');