【问题标题】:Lucee CFCs throw an XML errorLucee CFC 引发 XML 错误
【发布时间】:2015-11-03 01:37:35
【问题描述】:

我在 Ubuntu 14.04.3 LTS 上运行 Lucee 4.5.1.023。当我创建一个 .cfm 文件并执行 cfoutput 或 cfdump 时,输出与您期望的一样。但是,当我在 CFC 中使用函数并将函数设置为 output="true" 并执行 cfoutput 或 cfdump 时,结果是以下“XML Parsing Error: not well-formed”。

<cfcomponent>
    <cffunction name="test" access="remote" output="true">
        <cfoutput>#now()#</cfoutput>
    </cffunction>
</cfcomponent>

如果 output="false" 并且根本没有生成输出,则返回 XML 解析错误。例如

<cfcomponent>
    <cffunction name="test" access="remote" output="false">
        <cfset var a = 1>
    </cffunction>
</cfcomponent>

任何帮助或建议将不胜感激。

【问题讨论】:

  • 我知道这是一篇相当老的帖子,但它今天发生在我身上。为了解决这个错误,我添加了一个 `cfheader(name="Content-Type", value="text/html"); ` 在输出之前的函数中。像魅力一样工作。

标签: xml apache2 railo lucee


【解决方案1】:

我没有安装 lucee,但您的功能访问方法设置为“远程”。

我的假设是 lucee 服务器相应地尝试以 XML 格式返回响应。在您的函数调用中输出任何内容都将插入到生成的 XML 流中,这将破坏 XML。

对于调试,您可以将访问方法设置为“public”并将输出设置为 true。这将让您调试代码。事实上,除非您打算将 CFC 作为服务公开,否则最好不要使用“远程”。

您也可以在标准 cfml 页面中像这样调用您的方法。您可以在开发过程中显式设置这样一个页面来调试组件。

<cfset myComponent = createObject("mycomponent")>

<cfoutput>
    <cfset myComponent.myMethod()><!---  --->
</cfoutput> 

【讨论】:

  • 感谢您的回复。切换到“public”会导致以下错误“component [test] has no remote function with name [test]”。在过去(ColdFusion 或 Railo),将函数公开为“远程”允许它们被 Web 浏览器或通过 ajax 调用访问。
  • 因此怀疑 CFC 被称为 Web 服务。如果您发布您尝试调用该方法的方式,我很可能会为您提供一个关于如何调用该方法以进行测试的示例。
  • 那将非常有帮助。谢谢。
  • 我在现有答案中添加了一些代码,向您展示如何测试您的组件。创建新的 cfml 页面,然后使用 cod sn -p 调用组件。这样做会告诉服务器您只需要 HTML 作为响应。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
相关资源
最近更新 更多