Extract XML Response in PHP Example

Today, We want to share with you Extract XML Response in PHP Example.In this post we will show you Parse XML Response in PHP Example, hear for Interprets a string of XML into an object we will give you demo and example for implement.In this post, we will learn about Parsing SOAP responses with PHP’s SimpleXML with an example.

Extract XML Response in PHP Example

There are the Following The simple About Extract XML Response in PHP Example Full Information With Example and source code.

Also Read This πŸ‘‰   Convert XML to JSON in PHP

As I will cover this Post with live Working example to develop php xml to json with attributes, so the xml to json php manually for this example is following below.

XML File

simple XML structured string

properly formatted XML

<?xml version='1.0'?>
<business>
    <website>Pakainfo.com Blog</website>
    <createdby>Jaydeep Gondaliya</createdby>
    <devlopers>
        <devloper>
            <adminusername>Jaydeep</adminusername>
            <superadmin>Gondaliya</superadmin>
        </devloper>
        <devloper>
            <adminusername>Astha</adminusername>
            <superadmin>Bhanderi</superadmin>
        </devloper>
    </devlopers>
</business>

PHP Convert XML Response

PHP string variable called $xmlResponse

simplexml_load_string i PHP

$xml = simplexml_load_string($xmlResponse);

creating an array of our devlopers

PHP Create An Array

$devlopers = array();
foreach($xml->devlopers as $devloper) {
    $devloperObject = array(
        "adminusername" => $devloper->adminusername,
        "superadmin" => $devloper->superadmin
    );
    array_push($devlopers, $devloperObject);
}

add the devlopers array to a custom object

Also Read This πŸ‘‰   how to get values from xml object array in php?

$jsonObject = array(
    "website" => $xml->website,
    "createdby" => $xml->createdby,
    "devlopers" => $devlopers
);

PHP converting simple custom object using the Add to Json methods

Json::encode($jsonObject);

You can following onther way to PHP Convert XML to JSON

Parse An XML Response With PHP

JSON result of our XML response

Response For JSON

{
  "website": "Pakainfo.com Blog",
  "createdby": "Jaydeep Gondaliya",
  "devlopers": [
    {
      "adminusername": "Jaydeep",
      "superadmin": "Gondaliya"
    },
    {
      "adminusername": "Astha",
      "superadmin": "Bhanderi"
    }
  ]
}

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Extract XML Response in PHP Example.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.