I have a XML object that I need to convert to JSON for easier getting of values.
The XML object is as below:
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header xmlns:work='http://bea.com/2004/06/soap/workarea/'>
<work:WorkContext xmlns:wsu='http://schemas.xmlsoap.org/ws/2002/07/utility' xmlns:work='http://bea.com/2004/06/soap/workarea/'>
<java class='java.beans.XMLDecoder'>
<string>weblogic.app.MerchantQueryWebService</string>
<int>214</int>
<string>weblogic.workarea.StringWorkContext</string>
<string>2.0</string>
<string/>
</java>
</work:WorkContext>
</env:Header>
<env:Body>
<m:RequestTransactionByTimeIntervalResponse xmlns:m='http://www.zain.com/'>
<m:RequestTransactionByTimeIntervalResult>
<java:Status xmlns:java='java:com.obopay.ws.merchantquery.zain'>0</java:Status>
<java:TotalTransactions xmlns:java='java:com.obopay.ws.merchantquery.zain'>1</java:TotalTransactions>
<java:TotalAmount xmlns:java='java:com.obopay.ws.merchantquery.zain'>50</java:TotalAmount>
<java:Transactions xmlns:java='java:com.obopay.ws.merchantquery.zain'>[46139805#254734977477#50#Test]</java:Transactions>
<java:Message xmlns:java='java:com.obopay.ws.merchantquery.zain'>Success</java:Message>
</m:RequestTransactionByTimeIntervalResult>
</m:RequestTransactionByTimeIntervalResponse>
</env:Body>
</env:Envelope>
I tried this;
$fileContents = str_replace(array("\n", "\r", "\t"), '', $response);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
echo $json;
However, the response is {}
Nothing on the JSON.
I would like to get the values on env:Body
, any advice on this?
Anyone.