XML 通过的是 XML() 但在 ColdFusion 中的 xmlParse() 失败

XML that passes isXML() but fails xmlParse() in ColdFusion

我正在为一些看起来像这样的古老代码编写测试用例:

if (isXML(foo)) {
  try {
    bar = xmlParse(foo);
  }
  catch(any e) {
    // log error
  }
}

Blame 揭示了一些背景故事,表明我们看到一些 XML 字符串,其中 isXML 返回 true,但 xmlParse 抛出某种异常。

什么样的字符串会产生这种效果?

我试过放入一个我知道可以正常解析的字符串,然后在元素中添加了一个 &,但随后 isXML returns 为 false。我不确定还能尝试什么。

以下是 DOCSIsXml() 的使用详情:

This function determines whether text is well-formed XML, that is, it conforms to all XML syntax and structuring rules. The string does not have to be a complete XML document. The function does not validate against a Document Type Definition (DTD) or XML Schema.

因此,可能使用了某些命名空间但未找到定义。即,

<cfsavecontent variable="xml">
    <?xml version="1.0" encoding="UTF-8"?>
    <xyz:note>
      <xyz:to>Myself</xyz:to>
      <xyz:from>You</xyz:from>
      <xyz:heading>Reminder</xyz:heading>
      <xyz:body>Test</xyz:body>
    </xyz:note>
</cfsavecontent>
<cfset xml = trim( xml )>

<!--- Try to parse --->
<cfset isXmlParsable = TRUE>
<cftry>
    <cfset XmlParse( xml )>

    <cfcatch>

        <!--- Will come here as xyz namespace is not defined --->
        <cfset isXmlParsable = FALSE>
    </cfcatch>
</cftry>

<cfoutput>
    Is XML Valid: #IsXml( xml )#<br>
    Is XML Parsable: #isXmlParsable#
</cfoutput>

输出:

是否XML有效:是
XML 是否可解析:FALSE

这里是 GIST.