xml feed的代码无法正常工作

I'm trying to print an xml feed into my php page,but this code is not working correctly, and i have no idea why. It just shows the code as it is on the browser from xpath to ?> . Can anyone help me with this please

<html>
<head>
   <title>XML FEED</title>
 </head>
 <body>
   <ul>
   <?php
     $dom = simplexml_load_file("http://feeds.bbci.co.uk/news/rss.xml");
     foreach ($dom->xpath("/channel/item") as $item)
     {
        print "<li>";
        print $item->title;
        print "</li>";
     }
    ?>
  </ul>
</body>
</html>

Consider adjusting your XPath with double forward slashes as channel is not the root element:

foreach ($dom->xpath("//channel/item") as $item) {
    ...
}

Alternatively, use the root, rss, element in expression:

foreach ($dom->xpath("/rss/channel/item") as $item) {
    ...
}

I suspect your server is not configured to allow the short PHP tags (which is discouraged anyway) so Always use the full opening tag.

Since PHP is not parsing your code, the browse gets sent the following...

 <? . . . . . foreach ($dom->   

Which is not valid HTML, so it is not displayed, but if you view the source of your page, you will see more of your PHP code.

Simply starting your code with <?php will trigger PHP parsing, and things should work.