Artistdata.com RSS提要解析可以在本地进行,但不能在生产服务器上进行


Artistdata.com RSS Feed parsing works locally but not on production server

在过去的几天里,我一直在努力弄清楚为什么我的代码在本地运行良好,但在部署到生产服务器上时失败了。

我的本地测试环境是10.7.2 Lion iMac上的最新MAMP。

基本上,我需要从Artistdata.com获取某些XML RSS数据,以便将其插入到我正在开发的一个简单的PHP驱动的非CMS网站中

<!DOCTYPE html>
<html>
<head>
<title>RSS FEED Parser</title>
</head>
<body>
<?php
    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    # RSS Feed parser #
    function getFeed($feed_url) {
        $content = file_get_contents($feed_url);
        $x = new SimpleXmlElement($content);
        foreach ($x->show as $showEntry) {
            echo '<div>';# date
                $newDate = new DateTime($showEntry->date);
                echo date_format($newDate, 'l, F j, Y');
            echo '</div>';# /date
            # further data fetching, totally unrelated
            # to the problem that I'm experiencing
        }
    }
?>
<!-- START FEED PARSING -->
<div id="feed-data">
    <?php getFeed('http://feeds.artistdata.com/xml.shows/artist/AR-30CA266E4BEDD78F/xml/future'); ?>
</div>
<!-- END FEED PARSING -->
</body>
</html>

我相信有更多的人有类似的问题,但我还没有找到一个可行的解决方案。

如果你有什么建议,我将不胜感激。

编辑:忘记发布错误,所以它们在下面

Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : Space required after the Public Identifier in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : SystemLiteral " or ' expected in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 1: parser error : SYSTEM or PUBLIC, the URI is missing in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 9: parser error : Opening and ending tag mismatch: hr line 7 and body in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </body></html> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 9: parser error : Opening and ending tag mismatch: body line 4 and html in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: </body></html> in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 10: parser error : Premature end of data in tag html line 2 in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/*****/public_html/ssr/parse-feed.php on line 17
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/*****/public_html/ssr/parse-feed.php on line 17
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/*****/public_html/ssr/parse-feed.php:17 Stack trace: #0 /home/*****/public_html/ssr/parse-feed.php(17): SimpleXMLElement->__construct('<!DOCTYPE HTML ...') #1 /home/*****/public_html/ssr/parse-feed.php(33): getFeed('http://feeds.ar...') #2 {main} thrown in /home/*****/public_html/ssr/parse-feed.php on line 17

问题解决了,我使用了错误的提要,正确的是http://artistdata.sonicbids.com/john-latini/shows/xml/future

XML看起来不像RSS。它是由http://feeds.artistdata.com/_css/shows.xsd.

错误消息都表示您得到的是HTML(2.0)页面,而不是XML。我无法重现,我使用file_get_contents()获取XML。

尝试输出HTML页面,也许它包含更多信息。

echo file_get_contents('http://feeds.artistdata.com/xml.shows/artist/AR-30CA266E4BEDD78F/xml/future');