我想解析使用PHP的XML字符串中的單個元素。問題是這個單獨的元素出現在條目開始之前。 XML如下:如何使用PHP從XML解析單個條目?
<?xml version="1.0" encoding="UTF-8"?>
<feed gd:kind="shopping#products" gd:etag=""lm_25heFT8yiumci9EH1kItJBpg/Sj5O9aXZ82PKpx3N2C3uQYMhNYE"" xmlns="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:s="http://www.google.com/shopping/api/schemas/2010">
<openSearch:totalResults>64</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<entry >...</entry>
<entry >...</entry>
</feed>
我想解析出「opensearch:totalResults」標記中的「64」。我如何做到這一點,並將其分配給在PHP中的變量?我試過:
$url = 'url of xml feed';
$xml = simplexml_load_file($url);
$entries =$xml->entry[0]->openSearch:totalResults;
// also tried $entries =$xml->openSearch:totalResults;
echo $entries;
但它不工作。有什麼建議?
任何錯誤?.... – 2012-02-03 06:53:55
[simplexml_load_string:如何獲得在youtube的視頻源中的openSearch:itemsPerPage?](http://stackoverflow.com/questions/6301218/simplexml-load-string-how-以獲取opensearchitemsperpage-you-youtubes-video-fee) – salathe 2012-02-03 07:53:11
另請參閱:http://stackoverflow.com/search?q=%5Bsimplexml%5D+opensearch – salathe 2012-02-03 07:53:43