Jump to content

Why is my SimpleXML Object Null?


mtorbin

Recommended Posts

Hey all,

 

I'm probably missing something super easy, but for whatever reason, my simpleXML object call is coming back null.  Here is my code:

<?php
class VenueData {
public function __construct($key,$name) {
	$this->searchURL = 'http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=' . $key . '&limit=1&venue=' . $name;
	$this->searchXML = simplexml_load_file($this->searchURL);
	$this->venueMatches = $this->searchXML->venuematches->{venue};
	print(gettype($this->venueMatches) . "\n");
}
}
?>

 

Without giving away my key, here is a url that you can use to see the xml that's being pulled back:

 

http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=b25b959554ed76058ac220b7b2e0a026&venue=arena

 

Please help me figure out what I'm missing here.

 

Thanks,

 

- MT

Link to comment
https://forums.phpfreaks.com/topic/168838-why-is-my-simplexml-object-null/
Share on other sites

Ah, got it!  I didn't go up high enough on the chain:

<?php
class VenueData {
public function __construct($key,$name) {
	$searchURL = 'http://ws.audioscrobbler.com/2.0/?method=venue.search&api_key=' . $key . '&limit=1&venue=' . $name;
	$searchXML = simplexml_load_file($searchURL);

	foreach($searchXML->results->venuematches->venue as $venue) {
		print($venue->id . "\n");
	}
}
}
?>

 

- MT

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.