craft-fetch icon indicating copy to clipboard operation
craft-fetch copied to clipboard

Added XML support

Open jamiematrix opened this issue 5 years ago • 3 comments

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.

jamiematrix avatar Jan 02 '20 09:01 jamiematrix

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...

jalendport avatar Jul 19 '23 17:07 jalendport

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

jamiematrix avatar Jul 20 '23 09:07 jamiematrix

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

jamiematrix avatar Jul 24 '23 09:07 jamiematrix