我試圖從XML文件datafeed輸出數據,支持文件非常差,我無法通過XML循環。Catalyst XML datafeed
$request =
"<"."?xml version='1.0' encoding='iso-8859-1'?".">".
"<download account='XXXX' password='XXXX' version='6' request='EXP' format='XML' dealer='XXXX' vehicles='Y' />";
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/xml", "Content-Length: " . strlen($request)));
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'https://www.catalyst-findit.co.uk/download.php');
$response = curl_exec($ch);
$xml = simplexml_load_string($response);
print_r($xml);
我主要感興趣的車輛數據,我試圖加載由:
echo (string) $xml->vehicles->vehicle[0];
雖然這並不
SimpleXMLElement Object (
[@attributes] => Array (
[version] => 6 [type] => WEB [date] => 20120220)
[account] => SimpleXMLElement Object (
[@attributes] => Array (
[code] => XXXX
)
[sites] => SimpleXMLElement Object (
[site] => SimpleXMLElement Object (
[@attributes] => Array (
[code] => XXXX
)
[name] => Name [address1] => Address 1 [address2] => town [address3] => UK [county] => County [postcode] => Postcode [phone] =>[fax] =>
[vehicles] => SimpleXMLElement Object (
[vehicle] => Array (
[0] => SimpleXMLElement Object (
[@attributes] => Array (
[code] => 5956 [new] => N
[engineSize] => 998
[mileage] => 8000
[type] => MC
[reg] => XXX
[regDate] => 20070414
[created] => 20110928090130
[modified] => 20110928090130
) [manufacturer] => Honda
[description] => CBR 1000 RR-7
[colour] => Black
[body] => Motorcycle
[fuel] => Petrol
[status] => In Stock
)
[1] => SimpleXMLElement Object (
[@attributes] => Array (
[code] => 5958
[new] => Y
[engineSize] => 125
[type] => MC
[created] => 20110930090254
[modified] => 20110930090254
)
[manufacturer] => Honda
[description] => WW125EX2A
[colour] => BLACK(NHA35)
[body] => SCOOTER
[status] => In Stock
[category] => SCOOTER
)
)
)
)
)
)
的數據是由加載似乎工作。
不勝感激,如果有人可以提供任何建議:)
在此先感謝。
編輯 XML文件(只顯示兩個用於方便閱讀輛):
<?xml version="1.0" encoding="iso-8859-1"?>
<findit xmlns="http://www.catalyst-findit.co.uk/download" version="6" type="WEB" date="20120220">
<account code="XXX">
<sites>
<site code="BRI">
<name>XXX</name>
<address1>XXX</address1>
<address2>XXX</address2>
<address3>XXX</address3>
<county>XXX</county>
<postcode>XXX</postcode>
<phone>01472 123456</phone>
<fax>01472 123456</fax>
<vehicles>
<vehicle code="XXX" new="N" engineSize="998" mileage="8000" type="MC" reg="XXX" regDate="20070414" created="20110928090130" modified="20110928090130">
<manufacturer>Honda</manufacturer>
<description>CBR 1000 RR-7</description>
<colour>Black</colour>
<body>Motorcycle</body>
<fuel>Petrol</fuel>
<status>In Stock</status>
</vehicle>
<vehicle code="XXX" new="Y" engineSize="125" type="MC" created="20110930090254" modified="20110930090254">
<manufacturer>Honda</manufacturer>
<description>XXX</description>
<colour>BLACK(NHA35)</colour>
<body>SCOOTER</body>
<status>In Stock</status>
<category>SCOOTER</category>
</vehicle>
</vehicles>
</site>
</sites>
</account>
</findit>
什麼是錯誤?請嘗試'curl_error'得到錯誤 – maxjackie 2012-02-20 12:43:26
沒有顯示錯誤,'print_r'顯示上面的數據,我只是無法訪問車輛數據。 – Elliott 2012-02-20 12:47:33