Parse An XML Response With PHP

If you’re like me, you find XML a real pain to deal with, but yet it still seems to exist with various web services. If you’re using Android or AngularJS, these frameworks can’t process XML out of the box, but they can JSON.

With the assistance of a PHP powered web server, you can easily transform the nasty XML responses you get into something more usable like JSON.

PHP has a nifty method called simplexml_load_string and what it does is it loads an XML structured string into an easy to use object. Let’s say you have a string variable called $xmlResponse that has the following properly formatted XML in it:

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.