0
내가 검증 및 네임 스페이스에 대한 인식없이 XMLSlurper 만들 때 :.XMLSlurper : (거짓, 거짓) XmlSlurper를 사용할 때 찾을 수 없습니다 노드
new XmlSlurper(false, false)
I 이후 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
이 알려진 버그 아니면 내가 뭔가를 놓친 거지인가 :
다음 코드는 내 문제를 보여?
XML 네임 스페이스에 대한 지원을 제공하지 않기를 요청하는 경우 findAll 내부의 로직이'(node.name() == "xt : replace")'가 아니어야합니다. 그것은. – dmahapatro
예, "xt : replace"를 찾으면 노드가 발견됩니다. 나는 "namespaceAware"가 무엇을 의미하는지에 대해 다른 이해를 가지고있었습니다. 나는 그것이 네임 스페이스를 무시하는 것을 의미한다고 생각했다. 콜론은 네임 스페이스 할당을 위해 예약되어 있으므로 요소 이름에는 콜론이 포함될 수 없습니다. 그러나 여기서 "xt :"접두사는 이름의 일부로 취급됩니다. XmlSlurper 동작이 혼란 스럽습니다. 또한 일반적인 네임 스페이스 접두사가 변경되면 프로그램이 작동을 멈 춥니 다. – KarelHusa
그렇다면'def envelope1 = new XmlSlurper (false, true) .parseText (xml)'을 사용하지 마십시오. 유효성 검사가 꺼져 있지만 네임 스페이스를 인식하고 있습니다 ... –