我在使用SimpleXML讀取Spreadshirt API中的屬性時遇到了困難。我無法從資源中獲取xlink:href屬性,這是我所需要的,因爲它不會顯示在收到的數據中。似乎能夠抓住一切,但。PHP XML xlink:href屬性
這是我讀的XML:
<articles xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.spreadshirt.net" xlink:href="http://api.spreadshirt.net/api/v1/shops/800323/articles?fullData=true" offset="0" limit="50" count="16" sortField="default" sortOrder="default">
<article isDuplicate="false" xlink:href="http://api.spreadshirt.net/api/v1/shops/800323/articles/100402428" id="100402428">
<name>Hammer T-Shirt</name>
<price>
<vatExcluded>13.33</vatExcluded>
<vatIncluded>16.00</vatIncluded>
<vat>20.00</vat>
<currency xlink:href="http://api.spreadshirt.net/api/v1/currencies/2" id="2"/>
</price>
<resources>
<resource mediaType="png" type="preview" xlink:href="http://image.spreadshirt.net/image-server/v1/products/125642560/views/1"/>
</resources>
</article>
</atricles>
這是從SimpleXML的回來的數據:
SimpleXMLElement Object
(
[@attributes] => Array
(
[isDuplicate] => false
[id] => 27368595
)
[name] => Hammer Boxers
[price] => SimpleXMLElement Object
(
[vatExcluded] => 10.00
[vatIncluded] => 12.00
[vat] => 20.00
[currency] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 2
)
)
)
[resources] => SimpleXMLElement Object
(
[resource] => SimpleXMLElement Object
(
[@attributes] => Array
(
[mediaType] => png
[type] => preview
)
)
)
)
有沒有人有什麼想法?我很難過。
您不顯示返回的數據。要顯示數據,使用** SimpleXMLElement **對象的' - > asXML('php:// output')'方法,不要使用'print_r'或'var_dump',這些函數隱藏任何對象的數據。 – hakre 2014-12-22 11:32:15