如何检索xml文件中的两个元素实例
这是我如何得到其他人
$LargeImage = $xml->Items->Item->LargeImage->URL;
$author = $xml->Items->Item->ItemAttributes->Author;
echo ($author);
然而对于$ author,有2位作者,元素就像这样
Items->Item->ItemAttributes->
<Author>Ralph Bravaco</Author>
<Author>Shai Simonson</Author>
所以我目前的代码只能找回第一位作者
答案 0 :(得分:1)
$xml = new SimpleXMLElement($string);
$result = $xml->xpath('/Items/Item/ItemAttributes/Author');
while(list( , $node) = each($result)) {
echo $node,"\n";
}
答案 1 :(得分:1)
试试这个:
foreach($xml->Items->Item->ItemAttributes->Author as $author) {
echo (string)$author.'<br>';
}
它将回应所有作者,无论不是。作者。
答案 2 :(得分:0)
我想你要求这个 -
echo $author = $xml->Items->Item->ItemAttributes->Author[0];
echo $author = $xml->Items->Item->ItemAttributes->Author[1];