2012-05-10 4 views
1

Я пытаюсь проанализировать структуру xml веб-сайта ebay после реализации их API. Я получаю нулевые значения для элементов «categoryId» и «currentPrice». Пожалуйста, что я делаю неправильно. Найти мой PHP код ниже:parse ebay xml response

<?php 

// http get url *** 

$url =("http://svcs.sandbox.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsByKeywords&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=Linkserv-9a06-4300-982e-769819b827e9&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&keywords=shirts&paginationInput.entriesPerPage=20&paginationInput.pageNumber=1"); 

$xml = simplexml_load_file($url); 

foreach ($xml->searchResult->item as $entry){ 
echo $entry->itemId; 
echo $entry->title; 
echo $entry->categoryId; 
echo $entry->categoryName; 
echo $entry->viewItemURL; 
echo $entry->location; 
echo $entry->currentPrice; 

// Process XML file 
// Opens a connection to a PostgresSQL server 
$connection = pg_connect("dbname=postgres user=postgres password=xxxx"); 
$query = "INSERT INTO ebay(id, title, catid, category, image, location, price) VALUES ('" . $entry->itemId . "', '" . $entry->title . "', '" . $entry->categoryId . "', '" . $entry->categoryName . "', '" . $entry->viewItemURL . "', '" . $entry->location . "', '" . $entry->currentPrice . "')"; 

$result = pg_query($query); 
pg_close(); 
} 

?> 

Благодаря

ответ

1

вы могли бы попробовать:

echo $entry->primaryCategory->categoryId 
echo $entri->sellingStatus->currentPrice 
+0

Как добавить продукт в Ebay с помощью синтаксического анализа URL, пожалуйста, помогите мне исправить любой код для меня .. спасибо –