Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

non-object and invalid argument

Posted on 2011-03-10
3
Medium Priority
?
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
zappafan2k2 earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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.

705 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