Solved

non-object and invalid argument

Posted on 2011-03-10
3
310 Views
Last Modified: 2013-12-13
Hi,

I have a problem with reading an xml file... and am not sure why I'm getting the error.
So here is a part of the xml:

<status>
<shard name="Blightweald" online="True" locked="False" population="high" queued="0" language="English" pvp="False" rp="False" recommend="False"/>
<shard name="Cloudborne" online="True" locked="False" population="high" queued="0" language="English" pvp="True" rp="False" recommend="False"/>
<shard name="Steampike" online="True" locked="False" population="high" queued="0" language="English" pvp="False" rp="False" recommend="False"/>
</status>

Open in new window



and here is my code:
$url = "http://eu.riftgame.com/en/status/eu-status.xml";

		// READ THE EXTERNAL DATA
		$xml = simplexml_load_file($url);

		foreach ($xml->status["shard"] as $shard)
		{
			if ($shard["name"] == "Blightweald")
			{
				echo $shard->name;
				echo $shard->population;
			}
		}

Open in new window


I even tried setting
$xml->status["shard"]

to

$xml->status->shard

But no use. That would be an invalid argument.

Any ideas?
0
Comment
Question by:Mutsop
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
zappafan2k2 earned 500 total points
ID: 35103085
When figuring this stuff out, print_r() is always helpful.  By running print_r($xml), I found that PHP was making "status" the root.

Try this:

$url = "http://eu.riftgame.com/en/status/eu-status.xml";

      // READ THE EXTERNAL DATA
      $xml = simplexml_load_file($url);

      foreach ($xml->shard as $shard)
      {
         if ($shard['name'] == "Blightweald")
         {
            echo $shard['name'];
            echo $shard['population'];
         }
      }

Open in new window

0
 
LVL 3

Author Comment

by:Mutsop
ID: 35103516
Oh okay... Well I thought the root had to be set too :)
Thanks, it works like a charm
0
 
LVL 3

Author Closing Comment

by:Mutsop
ID: 35103534
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
change password links 7 74
php email 2 26
Saving image into server to get url later 1 31
myqsl update statement on phpMyAdmin 8 22
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now