XMLSlurper:使用 XmlSlurper 时找不到节点(false,false)

XMLSlurper: No nodes found when using XmlSlurper(false, false)

当我在没有验证和名称空间感知的情况下创建 XMLSlurper 时:

new XmlSlurper(false, false)

我随后无法使用 node.depthFirst().findAll().

找到任何节点

以下代码说明了我的问题:

def xml = '''<?xml version="1.0" encoding="UTF-8"?>
<cus:Customizations xmlns:cus="http://www.bea.com/wli/config/customizations" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xt="http://www.bea.com/wli/config/xmltypes">
    <cus:customization xsi:type="cus:EnvValueActionsCustomizationType">
        <cus:description/>
        <cus:actions>
            <xt:replace>
                <xt:envValueType>Service URI</xt:envValueType>
                <xt:location>0</xt:location>
                <xt:value xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema">http://myUrl.com</xt:value>
            </xt:replace>
        </cus:actions>
    </cus:customization>
</cus:Customizations>'''

/* The following code finds no nodes. */
def envelope1 = new XmlSlurper(false, false).parseText(xml)
def replaces1 = envelope1.depthFirst().findAll { node ->
    (node.name() == "replace")
}
assert replaces1.size() == 0

/* The following code finds one node (works as I expect). */
def envelope2 = new XmlSlurper().parseText(xml)
def replaces2 = envelope2.depthFirst().findAll { node ->
    (node.name() == "replace")
}
assert replaces2.size() == 1

这是一个已知错误还是我遗漏了什么?

当 XmlSlurper 的 属性 namespaceAware 设置为 false 时,我们需要将命名空间前缀视为元素名称的一部分,即当我们查找元素时:

(node.name() == "xt:replace")

XmlSlurper 的这种行为对我来说似乎不正确,但它就是这样工作的。双冒号 (:) 不能是 XML 元素名称的一部分,并且保留供命名空间使用。我的结论是,以后我会使用 namespaceAware 设置为 true。

感谢@dhamapatro 的帮助。