我想從eBay api獲取一些信息並將其存儲在數據庫中。我用簡單的XML來提取信息,但我有一個小問題,因爲某些項目的信息不顯示。如果我打印到simple_xml,我可以很清楚地看到這些信息是由eBay api提供的。 我php,SimpleXML,while循環
$items = "220617293997,250645537939,230485306218,110537213815,180519294810";
$number_of_items = count(explode(",", $items));
$xml = $baseClass->getContent("http://open.api.ebay.com/shopping?callname=GetMultipleItems&responseencoding=XML&appid=Morcovar-c74b-47c0-954f-463afb69a4b3&siteid=0&version=525&IncludeSelector=ItemSpecifics&ItemID=$items");
writeDoc($xml, "api.xml");
//echo $xml;
$getvalues = simplexml_load_file('api.xml');
// print_r($getvalue);
$number = "0";
while($number < 6) {
$item_number = $getvalues->Item[$number]->ItemID;
$location = $getvalues->Item[$number]->Location;
$title = $getvalues->Item[$number]->Title;
$price = $getvalues->Item[$number]->ConvertedCurrentPrice;
$manufacturer = $getvalues->Item[$number]->ItemSpecifics->NameValueList[3]->Value;
$model = $getvalues->Item[$number]->ItemSpecifics->NameValueList[4]->Value;
$mileage = $getvalues->Item[$number]->ItemSpecifics->NameValueList[5]->Value;
echo "item number = $item_number <br>localtion = $location<br>".
"title = $title<br>price = $price<br>manufacturer = $manufacturer".
"<br>model = $model<br>mileage = $mileage<br>";
$number++;
}
上面的代碼返回
item number = localtion = title = price = manufacturer = model = mileage = item number = 230485306218 localtion = Coventry, Warwickshire title = 2001 LAND ROVER RANGE ROVER VOGUE AUTO GREEN price = 3635.07 manufacturer = Land Rover model = Range Rover mileage = 76000 item number = 220617293997 localtion = Crawley, West Sussex title = 2004 CITROEN C5 HDI LX RED price = 3115.77 manufacturer = Citroen model = C5 mileage = 76000 item number = 180519294810 localtion = London, London title = 2000 VOLKSWAGEN POLO 1.4 SILVER 16V NEED GEAR BOX price = 905.06 manufacturer = Right-hand drive model = mileage = Standard Car item number = localtion = title = price = manufacturer = model = mileage =
正如你所看到的信息是不是幾個項目檢索...如果我更換$號人工如「$ = ITEM_NUMBER $ getvalues->第[4] - >的ItemID;」適用於任何數量。
非常感謝!我已將您的答案標記爲「已接受」。如果您不介意,請讓我知道一個「穩定」的解決方案來獲得製造商,型號和里程數? ebay API在樹中顯示這些信息作爲名稱和值,但有時數組號會不同,因爲某些項具有更多「特定」。請看這裏的一個xml文檔的例子http://pastebin.com/NrvUdg8F 和簡單的XML的打印是http://pastebin.com/hY40YrWV –
Michael
2010-06-17 23:28:57
@Michael你可能不得不通過使用' foreach'看看你正在尋找的財產是否在那裏。 – 2010-06-17 23:35:58
再次感謝Pekka!你讓我今天一整天都感覺很好 ! – Michael 2010-06-17 23:40:38