如何从api请求中读取XML数据

问题描述:

I am making a call to some url : http://example.com/Service.asmx/getTodaysDiscussionForum which is xml data please see screenshot :enter image description here

$response = file_get_contents('http://103.1.115.87:100/Service.asmx/getTodaysDiscussionForum');

$response = new SimpleXMLElement($response);

print_r($response);exit;

it display following output :

SimpleXMLElement Object ( 
         [Table1] => Array ( [0] => SimpleXMLElement Object ( 
                                      [Id] => 1210 [Title] => Test Discussion, Dont Reply [CreatedDate] => 4/25/2014 10:42:49 AM 
                                      [Status] => Not Sent ) 
                             [1] => SimpleXMLElement Object ( 
                                      [Id] => 1182 [Title] => Negotiation Skills discussion [CreatedDate] => 4/25/2014 7:47:51 AM 
                                      [Status] => Not Sent )
                           )  
                        )

How can I store each data in a variables ?

I am new to this xml reading thanks in advance

$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml); 
$array = json_decode($json,TRUE);

<?php

foreach($response[0] as $data) {
        $id = $data->Id;
        //...
}