Take the 2-minute tour ×

I need to use an external XML file, I've tried different methods to read the file but can't reach what I want.

I used DOMDocument simplexml_load_file


$xml = simplexml_load_file("http://www.isecur1ty.org/InternetThreat/ThreatLevel.xml");

echo $xml->getName() . "<br />";

    echo $child->getName() . ": " . $child . "<br />";


But can't get it working with me!!

Here is the XML file:


As you can see, there are multi-levels. I need to get the values of each attribute (mainly under "level"), getting the version would be also ok.

Can somebody tell me how to do this?


share|improve this question

closed as too localized by Gordon, tereško, mkoryak, kapa, bmargulies Jun 11 '12 at 2:13


What doesn't work about your code? That information would be extremely helpful to anyone helping you. –  Vulcan Jun 10 '12 at 8:48
@Vulcan : Check the answers below :) –  sikas Jun 10 '12 at 9:01
add comment

2 Answers

Access them like this:

    echo $xml->level->date;
share|improve this answer
I just figured it out just before you added the answer :) .. Thanks. –  sikas Jun 10 '12 at 8:51
add comment
up vote 1 down vote accepted

OK, Got it :D

here is the solution, hope anyone can find it useful.


    $file = 'http://www.isecur1ty.org/InternetThreat/ThreatLevel.xml';
    if(!$xml = simplexml_load_file($file))
        exit('Failed to open '.$file);
    print_r($xml);  echo "<br />";
    echo "Current Level : " . $xml->level->current . "<br />" .
        "Previous Level : " . $xml->level->previous . "<br />" . 
        "Status : " . $xml->level->status . "<br />" . 
        "Date : " . $xml->level->date . "<br />" . 
        "Version : " . $xml->version . "<br />"

share|improve this answer
I hope so too... –  jos Jun 10 '12 at 12:09
add comment
