When it comes to secure and reliable to E-commerce platform that provides good customer experience along with lightning fast speed, Magento stands first. Every day a developer wakes up to create & develop something new to improve existing Magento E-commerce experience in such a way that can help store owners to increase revenue as well as enhance the customer shopping experience. By default, Magento 2 is very secure & handy with easy to use design interface that easily interact with various API and gateways to send & receive data. Recently we have been working on Magento based CURL project with one of the gateways in which we have to send data to the server and store received response into an object so we can easily use that response for the further development.

Also, meanwhile developing shipping & gateway extension, we came across the requirement where we need to get all the response data in an array and wanted to display it in such format.
So, here is how we have converted CURL XML response into an array in Magento 2 without any kind of hardcoding.

All you need to do is, just load up the XML in SimpleXML and use it directly as shown below.

Now you know that how to store response, you can try it on different XML feeds from various APIs. Hit the stars below if it worked for you and comment down if you face any issue while implementing the code.
Happy Coding!

Click to rate this post!
[Total: 10 Average: 4.4]