4 Replies - 1334 Views - Last Post: 28 November 2012 - 11:41 PM

#1 PMG1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 16-July 12

PHP parsing XML from Web Service

Posted 26 November 2012 - 10:37 PM

First of all, I have tried researching with Google to no success. I have a web service that is returning XML, but I can not find a way to parse it that works. I have tried simplexml in many different ways and it's just not working. I am unexperienced with PHP and could use some help. I am creating an website that uses this web service or one just like it to get its information. I need to be able to pick out certain data from the XML and use it in my code.

 <?php

$url = "https://my-test.illinoisstate.edu/service/it363/directory";
$params = array(
	"uid" => "833330103"
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, count($params));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));

$result = curl_exec($ch);
curl_close($ch);

header("content-type: text/xml");
echo $result;

$xml = simplexml_load_string($result);

echo $xml['uid'];





Is This A Good Question/Topic? 0
  • +

Replies To: PHP parsing XML from Web Service

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,028
  • Joined: 08-June 10

Re: PHP parsing XML from Web Service

Posted 26 November 2012 - 11:53 PM

I would expect line #24 not to work. afaik, SimpleXMLElement does not implement the ArrayAccess interface. so Id go for $xml->uid.
Was This Post Helpful? 0
  • +
  • -

#3 PMG1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 16-July 12

Re: PHP parsing XML from Web Service

Posted 27 November 2012 - 01:12 AM

View PostDormilich, on 26 November 2012 - 11:53 PM, said:

I would expect line #24 not to work. afaik, SimpleXMLElement does not implement the ArrayAccess interface. so Id go for $xml->uid.


Thanks, but I have tried and that doesn't show anything either.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3480
  • View blog
  • Posts: 10,028
  • Joined: 08-June 10

Re: PHP parsing XML from Web Service

Posted 27 November 2012 - 01:25 AM

then your only choice is to make a dump: var_dump($xml);
Was This Post Helpful? 1
  • +
  • -

#5 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: PHP parsing XML from Web Service

Posted 28 November 2012 - 11:41 PM

If in doubt, always var_dump() variable to see what's actually inside. Guessing is no good, really.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1