-1

Possible Duplicate:
How to get values of xml elements?

I have the following data structure but I am unsure what sequance I would use to get the id out of the array.

I have another XML document that works fine and I have accessed the variables like this

$mainPropertyUrl = simplexml_load_file("URL");
$mainPropertyDetails = $mainPropertyUrl->Attributes;

With the one below I have had to login via a HTTP Authentication Request and have used the following structure to generate belows code:

Generation PHP:

$oPMainUrl = 'HTTPS URI';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $oPMainUrl);  
curl_setopt($ch, CURLOPT_USERPWD, "username:pw");
$result = curl_exec($ch);
curl_close($ch);

$MainURI = simplexml_load_string($result);

$ID = $MainURI->properties->property->id;

I have tried the following:

PHP:

property[0]->attributes[3]->id;

XML:

object(SimpleXMLElement)#112 (10) {
  ["@attributes"]=>
  array(3) {
    ["approved"]=>
    string(30) "Sat Oct 27 17:57:29 +1300 2012"
    ["last_updated"]=>
    string(30) "Sat Oct 27 17:57:29 +1300 2012"
    ["id"]=>
    string(6) "278882"
  }
Community
  • 1
  • 1
Jess McKenzie
  • 8,345
  • 27
  • 100
  • 170

1 Answers1

1

assuming your object is $xml:

$attr = $xml->attributes(); // returns an assoc array
echo 'ID='.$attr['id'];

I think you can also do this:

$xml['id'];
Micah
  • 96
  • 1
  • 7