首页 文章

无法使用ColdFusion解析远程RSS提要

提问于
浏览
1

我'm having a vexing time displaying a remote RSS feed on an intranet site. I'm使用MM_ XSLTransform.cfc版本0.6.2来提取feed和一个基本的xsl输出 . Feed网址为www.fedsources.com/FedsourcesNet/RssFeeds/RSS_MarketFlash.aspx . 如果您在浏览器中打开它,您会看到它似乎是一个普通的RSS源 . 但是当我尝试在CF中显示它时,我得到以下" MM_ XSLTransform error. www.fedsources.com/FedsourcesNet/RssFeeds/RSS_ MarketFlash.aspx is not a valid XML document. Parsing www.fedsources.com/FedsourcesNet/RssFeeds/RSS_ MarketFlash.aspx An error occured while Parsing an XML document. Content is not allowed in prolog."(实际错误包括URL中的http:// . 然后,作为错误消息的一部分转储了订阅源 .
特别令人沮丧的是,如果我查看RSS的来源并将其复制并粘贴到文本文件中,然后解析该文本文件,它就会显示正常 . 运行CF版本7 .
我尝试将字符集从UTF-8更改为windows-1252,但是在开头添加了一些奇怪的字符并没有帮助 . 我也试图剥离 <channel >和 <item 之间的所有内容,但这没有帮助 .
我've successfully parsed other RSS feeds outside our firewall using the same code. Is there something about the aspx extension that'导致错误?有什么想法吗?任何人?
谢谢 .

1 回答

  • 3

    's the exact code that you'用于解析XML文档的内容是什么?如果您在文档中的 <?xml?> 标记之前有一些数据,通常会发生此特定错误,即使单个空格也可能导致问题 .

    我不熟悉你提到的特定CFC,所以我不能为你排除故障,但要确保你使用Trim函数围绕你要尝试解析的任何XML内容 .

    更新:谷歌的快速搜索引导我阅读本·纳德尔的这篇文章:http://www.bennadel.com/blog/1206-Content-Is-Not-Allowed-In-Prolog-ColdFusion-XML-And-The-Byte-Order-Mark-BOM-.htm

    您需要从Feed中删除字节顺序标记 . 此代码可以正常运行:

    <cfhttp method="get" url="http://www.fedsources.com/FedsourcesNet/RssFeeds/RSS_MarketFlash.aspx" />
    <cfset xmlResult = XmlParse(REReplace( cfhttp.FileContent, "^[^<]*", "", "all" )) />
    <cfdump var="#XMLParse(xmlResult)#" />
    

相关问题