craft-fetch
craft-fetch copied to clipboard
Added XML support
Default set to JSON, but there's now support if the endpoint is returning XML. Currently XML attributes are not returned (other than from the parent node), but that's next on the list.
I wonder if Symfony's XmlEncoder may be a better solution here than simplexml_load_string
and json_encode
/json_decode
?
If I'm not mistaken it's already included in Craft, and the implementation would look something like this:
use Symfony\Component\Serializer\Encoder\XmlEncoder;
...
$xmlEncoder = new XmlEncoder();
$body = $xmlEncoder->decode($response->getBody(), 'xml');
@jamiematrix let me know what you think...
I'll give it a go @jalendport thanks.
I blame Google in a way :) The change was a quick search for a project, simple_load_string
worked for me at the time. I think the key reason was for the LIBXML_NOCDATA
usage as the endpoint has a multitude of CDATA usage
I got Class 'Symfony\Component\Serializer\Encoder\XmlEncoder' not found
when usingXmlEncoder
- not sure if it was added in a later version of Craft? This site is on 3.6.18 at the moment