我正在为一些看起来像这样的古老代码编写测试用例: if (isXML(foo)) { try { bar = xmlParse(foo); } catch(any e) { // log error }} Blame揭示了一些背景故事,表明我们看到一些XML字符串,其中isXML返回tr
          if (isXML(foo)) {
  try {
    bar = xmlParse(foo);
  }
  catch(any e) {
    // log error
  }
} 
 Blame揭示了一些背景故事,表明我们看到一些XML字符串,其中isXML返回true,但是xmlParse引发了某种异常.
什么样的字符串会产生这种效果?
我已经尝试输入一个我知道可以解析的字符串,然后添加一个&在元素中,但isXML返回false.我不知道还有什么可以尝试的.
以下是 DOCS中IsXml()的使用细节: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可解析:错误
这是GIST.
