-1

I want to convert this output http://www.akwl.de/notdienst/xml.php?a=3&m=koord&w=51.954541;7.614748&z=2012-1-16;2012-1-22 into a styleable html.

This was my try...

<?php 
$xmlFile = 'http://www.akwl.de/notdienst/xml.php?a=3&m=koord&w=51.954541;7.614748&z=2012-1-16;2012-1-22';  
if (file_exists($xmlFile)) { 
    $xml = simplexml_load_file($xmlFile); 
    foreach ( $xml->interpret as $user )   
        {   
               echo 'Id: ' . $user['id'] . '<br>';   

           echo 'Datum: ' . $user->datum . '<br>';   
           echo 'Apotheke: ' . $user->Apotheke . '<br><br>';       
        }   

} else { 
    exit("File $xmlFile not found."); 
} 
?>
  • 1
    ...Right, what output are you getting.... – Nick R Jan 31 '14 at 13:23
  • File http://www.aknr.de/notdienst/exporte/xml.php?m=koord&w=51.494088;6.772776&z=2014-01-01;2014-01-31&a=2&c=iso not found. – minimalillusions Jan 31 '14 at 13:30
  • The problem here is that `file_exists` looks at the local file system, and not the remote server, and since you don't have that file locally - it will run the `else` part of the statement. Although this question has already been answered here : http://stackoverflow.com/a/5434164/2470724 – Nick R Jan 31 '14 at 13:41
  • 1
    To output an xml file as html you can use xslt transformation. This is the most flexible way. See [http://www.php.net/manual/en/book.xsl.php](http://www.php.net/manual/en/book.xsl.php) – Arjan Bas Jan 31 '14 at 13:12

1 Answers1

1

The problem here is that file_exists looks at the local file system, and not the remote server, and since you don't have that file locally - it will run the else part of the statement.

You could do something like this:

<?php 

    $file = 'http://www.aknr.de/notdienst/exporte/xml.php?m=koord&w=51.494088;6.772776&z=2014-01-01;2014-01-31&a=2&c=iso';

    if(!$xml = simplexml_load_file($file)){
        echo "file not found!";
    } else {
        echo "<pre>";
        print_r($xml);
        echo "</pre>";    
    }

?>

Then you can loop over the elements, and display the data,

Nick R
  • 7,704
  • 2
  • 22
  • 32