Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.5, 2.4.6
-
None
Description
When using GPathResult with XmlSlurper, if an attribute is in a namespace, you must retrieve it using the namespace prefix defined in the document and not that defined by declareNamespace. This issue prevents safe retrieval of namespaced XML attributes since the document generator is free to choose namespace prefix.
def text = """<x:root xmlns:x="blah"> <x:child x:id='1'>c</x:child> </x:root>""" def xml = new XmlSlurper() .parseText(text) .declareNamespace(x:'blah') // .declareNamespace(t:'blah') println xml.child.text() //"c" always println xml.'x:child'.text() //"c" when declareNamespace x, else "" println xml.'t:child'.text() //"c" when declareNamespace t, else "" println xml.child.'@x:id' //"1" always println xml.child.'@t:id' //"" always
Looking in the debugger, there is namespaceMap and namespaceTagHints in GPathResult. namespaceMap is updated by declareNamespace but namespaceTagHints is not, and namespaceTagHints is used when looking up attributes. I don't see a way to update namespaceTagHints and namespaceMap doesn't really even seem to be used.
Attachments
Issue Links
- relates to
-
GROOVY-7808 XmlSlurper unprefixed attributes should not be in the default namespace
- Closed