Solved

non-object and invalid argument

Posted on 2011-03-10
3
307 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

706 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

13 Experts available now in Live!

Get 1:1 Help Now