[ https://issues.apache.org/jira/browse/GROOVY-7781?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
John Wagenleitner resolved GROOVY-7781. --------------------------------------- Resolution: Fixed Assignee: John Wagenleitner Fix Version/s: 2.4.7 Thanks for reporting the issue and for reviewing and commenting on the proposed fix, really appreciate it. > GPathResult: Cannot retrieve XML attribute with namespace > --------------------------------------------------------- > > Key: GROOVY-7781 > URL: https://issues.apache.org/jira/browse/GROOVY-7781 > Project: Groovy > Issue Type: Bug > Components: XML Processing > Affects Versions: 2.4.5, 2.4.6 > Reporter: Jason Winnebeck > Assignee: John Wagenleitner > Fix For: 2.4.7 > > > 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. > {code} > 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 > {code} > 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. -- This message was sent by Atlassian JIRA (v6.3.4#6332)