0
を使用している場合が見つかりませんノード:。XMLSlurper:私は検証と名前空間意識することなくXMLSlurperを作成すると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
は、それが既知のバグですか、私は何かが足りないのですか?
XMLネームスペースのサポートを提供しないようにパーサに依頼する場合、findAll内のロジックは '(node.name()==" xt:replace ")'であるべきではありません。そうです。 – dmahapatro
はい、「xt:replace」を検索すると、そのノードが見つかります。私は "namespaceAware"が何を意味するのかをはっきりと理解していませんでした。私はそれが名前空間を無視することを意味すると仮定した。私が知る限り、コロンは名前空間の割り当てのために予約されているため、要素名にコロンを含めることはできません。しかし、ここでは "xt:"接頭辞は名前の一部として扱われます。 XmlSlurperの動作が混乱しているようです。また、一般的な名前空間接頭辞が変更された場合、プログラムは動作しなくなります。 – KarelHusa
なぜ、 'def envelope1 = new XmlSlurper(false、true).parseText(xml)'を使用しないと、検証は無効になりますが、名前空間を認識しています... –