0

この xml オブジェクトがあり、それぞれの "p" $xml->query->search["p"][0]->attribute["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
                                        )
                                )
                        )
                )
        )
)
4

1 に答える 1

1

このようにxpathを使用できます

$titles = $o->xpath('query/search/p/@title');

または、ドキュメント内のすべてのタイトル属性を取得するには

$titles = $o->xpath('//@title');
于 2013-09-20T10:28:51.433 に答える