嘿,我有一個simpleXMLElement文檔,其中包含一組數據以處理藝術家的相冊。PHP中的XML循環語句
下面是XML
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[num] => 3
[type] => artist
)
[title] => DJ Tiësto
[uri] => http://www.discogs.com/artist/DJ+Ti%C3%ABsto
[summary] => DJ Tiësto Tijs Michiel Verwest Dutch trance DJ & producer.
在這個XML文檔的提取物有多種不同類型的藝術家,從信息到專輯的標題信息。我想提取這些數據的某些部分並將它們回顯出來。例如,我想提取具有爲藝術家定義的[類型]的數組條目的摘要。我猜我會使用通過所有條目的foreach循環,並檢查這是否屬實?這是正確的方式去解決它。
我爲我的困惑解釋道歉
---- ----編輯
繼承人的PHP代碼,抓住數據 -
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.discogs.com/search?type=all&" .
"q=DJ+Tiësto&" .
"f=xml&" .
"api_key=<key>");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_ENCODING, "gzip");
$result = curl_exec($curl);
curl_close($curl);
$xmlmusic = new SimpleXMLElement($result,NULL,true);
foreach ($xmlmusic as $xm)
{
$attrs = $xm->attributes();
if($attrs["type"] == "title")
echo $xm->summary."\n";
}
>
你應該先嚐試一下,節省一些時間。 – Galen 2011-04-29 20:26:15
[一個簡單的程序到xml文件的CRUD節點和節點值]的可能的重複(http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of -xml文件) – Gordon 2011-04-29 20:29:23
可能的重複[如何訪問元素屬性與SimpleXml](http://stackoverflow.com/questions/4625045/how-to-access-element-attributes-with-simplexml) – Gordon 2011-04-29 20:31:18