groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Winnebeck (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7781) GPathResult: Cannot retrieve XML attribute with namespace
Date Mon, 04 Apr 2016 14:09:25 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15224196#comment-15224196
] 

Jason Winnebeck commented on GROOVY-7781:
-----------------------------------------

Not sure if GH comments get copied to here, but I did check out the pull request, and it looks
like the changes I would expect and the unit test looks like it would properly reproduce the
bug as well as pass when the fix is good.

> 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
>
> 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)

Mime
View raw message