jalendport / craft-fetch

Utilise the Guzzle HTTP client from within your Craft templates.
MIT License
24 stars 13 forks source link

Added XML support #7

Open jamiematrix opened 4 years ago

jamiematrix commented 4 years ago

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.

jalendport commented 1 year ago

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

jamiematrix commented 1 year ago

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 commented 1 year ago

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