Saturday, 6 December 2014

PHP XML Attributes



I'm having trouble reading attributes from the Spreadshirt API with SimpleXML. I can't grab the xlink:href attribute from resources, which is what I need as it's not displays in the data received. Seem to be able to grab everything else, though.


This is the XML I'm reading in:



<articles xmlns:xlink="http://ift.tt/PGV9lw" xmlns="http://ift.tt/1wcwkCJ" xlink:href="http://ift.tt/1wcwj1G" offset="0" limit="50" count="16" sortField="default" sortOrder="default">
<article isDuplicate="false" xlink:href="http://ift.tt/1wcwj1I" id="100402428">
<name>Hammer T-Shirt</name>
<price>
<vatExcluded>13.33</vatExcluded>
<vatIncluded>16.00</vatIncluded>
<vat>20.00</vat>
<currency xlink:href="http://ift.tt/1G07aqg" id="2"/>
</price>
<resources>
<resource mediaType="png" type="preview" xlink:href="http://ift.tt/1wcwjhY"/>
</resources>
</article>
</atricles>


This is the data coming back from 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
)

)

)

)


Does anyone have any ideas? I'm stumped.


No comments:

Post a Comment