我尝试解析具有困难命名空间的XML文件,但这不起作用。 希望你能帮我解决这个问题。
这是我的XML文件,它是从URL生成的:
<searchresultresponse xmlns="urn:veloconnect:catalog-1.1" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-1.0" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-1.0" xmlns:vct="urn:veloconnect:transaction-1.0" xmlns:vco="urn:veloconnect:order-1.1" xmlns:vcc="urn:veloconnect:catalog-1.1">
<vct:buyersid>417641</vct:buyersid>
<vct:responsecode>200</vct:responsecode>
<vct:transactionid>dmVsb2Nvbm5lY3Rfc2VhcmNoLkhJUl9TUkNfMTIwMg</vct:transactionid>
<vct:statuscode>2</vct:statuscode>
<startindex>0</startindex>
<count>500</count>
<totalcount>51691</totalcount>
<resultformat>ITEM_TYPE</resultformat>
<cac:item>
<cbc:description>BREMSBELAG GALFER ORGAN. FD171-G1054 (KBA)</cbc:description>
<cac:sellersitemidentification>
<cac:id>04303400</cac:id>
</cac:sellersitemidentification>
<cac:standarditemidentification>
<cac:id identificationschemeid="EAN/UCC-13">8400160001718</cac:id>
</cac:standarditemidentification>
<cac:manufacturersitemidentification>
<cac:id>FD171-G1054</cac:id>
<cac:issuerparty>
<cac:partyname>
<cbc:name>Galfer</cbc:name>
</cac:partyname>
</cac:issuerparty>
</cac:manufacturersitemidentification>
<cac:baseprice>
<cbc:priceamount amountcurrencyid="EUR">5.95</cbc:priceamount>
<cbc:basequantity quantityunitcode="EA">1</cbc:basequantity>
</cac:baseprice>
<cac:recommendedretailprice>
<cbc:priceamount amountcurrencyid="EUR">10.9</cbc:priceamount>
<cbc:basequantity quantityunitcode="EA">1</cbc:basequantity>
</cac:recommendedretailprice>
</cac:item>
我通过PHP从URL获取此信息:
<?php
error_reporting(E_ALL);
$url = "http://somedomain.com/feed";
set_time_limit(0);
$ch = curl_init($url);// or any url you can pass which gives you the xml file
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$xml = curl_exec($ch);
curl_close($ch);
$namespaces = $xml->getNameSpaces(true);
$cac = $xml->children($namespaces['cac']);
foreach ($xml as $entry){
$cac = $xml->children($namespaces['cac']);
echo $cac->item;
}
?>
我总是显示没有换行等的所有数据但是我需要获取特定对象以将它们保存在数组中(稍后)。
这里的名字真是有线。