gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 01:57:02 25 4
gpt4 key购买 nike

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

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

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

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

我试过放入一个我知道可以正常解析的字符串,然后在元素中添加一个 &,但是 isXML 返回 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.

因此,可能使用了某些 namespace 但未找到定义。即,

<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 .

关于在 ColdFusion 中通过 isXML() 但 xmlParse() 失败的 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50050724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com