Saibalu
Saibalu

Reputation: 113

Unable to print XML from webservice

I need to make a webservice call to target website and parse the xml response returned by it.

API :

http://targetwebsite/feed/product/tablets.xml?user=name&key=key

I am trying to print the xml first(transformation once printed) from the php code as follows

<?php
    $url = file_get_contents('http://targetwebsite/feed/product/tablets.xml?user=name&key=key');
    $xml = new SimpleXmlElement($url);
    print_r($xml);
?>

But unfortunately I don't see any xml response when I access my php file.

Upvotes: 1

Views: 104

Answers (1)

Kevin
Kevin

Reputation: 41885

Are you sure you're really using the correct url. It works just as fine:

$url = 'http://api.pricecheckindia.com/feed/product/mobile_phones/Samsung%20S4%20I9500.xml?user=saibrpwx&key=HGYMDNVKJGSPFQCP';
$xml = simplexml_load_file($url);

echo '<pre>';
print_r($xml);

It works here

Sidenote: To get useful information, try to turn on error reporting and put this on top of your PHP file:

error_reporting(E_ALL);
ini_set('display_errors', '1');

Supplemental info: As @Dave said in the comments, it might be worth looking on the ini settings about allow_url_fopen as you cannot make that request without it being open/turned on.

Upvotes: 1

Related Questions