xml - 检查 XML 是否存在特定键
问题描述
在以下 XML 中,我想查看是否存在名为“errors”的元素
<cfxml variable="sXML">
<?xml version="1.0" encoding="UTF-8"?>
<createTransactionResponse>
<messages>
<message>
<text>
<XmlText>The transaction was unsuccessful.</XmlText>
</text>
</message>
</messages>
<transactionResponse>
<errors>
<error>
<errorText>
<XmlText>The credit card number is invalid.</XmlText>
</errorText>
</error>
</errors>
</transactionResponse>
</createTransactionResponse>
</cfxml>
要查看是否存在节点“错误”,我使用了:
<cfif structKeyExists(sXML, "errors")>
但它又回来了false
(如果事务成功,则 XML 没有节点“错误”)。我做错了什么还是有更好的方法?
解决方案
推荐阅读
- python - 如何在mac上将python3.9设置为python3的默认值?
- javascript - 按钮在第一次点击时没有反应
- java - Java:返回 Int 值/多个值
- flexbox - flex-wrap:wrap 行不换行
- amazon-web-services - 使用 S3 + Glue + Athena 分析来自 EventBridge 的所有事件
- gradle - gradle 官方支持 johnrengleman 影子插件吗?
- c# - MVC 中的数据注释,按钮单击时未显示必需
- mysql - 如何选择借阅最多的书种
- c# - 将数据插入数据库时实体框架中的验证错误
- nix - vim 插件的自定义 Nix 派生失败