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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.