You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/04/03 06:42:25 UTC

[jira] [Commented] (GROOVY-7781) GPathResult: Cannot retrieve XML attribute with namespace

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

ASF GitHub Bot commented on GROOVY-7781:
----------------------------------------

GitHub user jwagenleitner opened a pull request:

    https://github.com/apache/groovy/pull/302

    GROOVY-7781 - Cannot retrieve XML attribute with namespace

    This change broke another test that asserted that an unprefixed attribute's namespace is the default namespace, but default namespace declarations do not apply to attribute names, see https://www.w3.org/TR/xml-names/#defaulting.
    
    > The namespace name for an unprefixed attribute name always has no value.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/jwagenleitner/groovy GROOVY-7781

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/302.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #302
    
----
commit 7b652bb329bc64fcaa978fef0778fc720d3e9029
Author: John Wagenleitner <jw...@apache.org>
Date:   2016-03-23T22:15:54Z

    GROOVY-7781 - Cannot retrieve XML attribute with namespace

----


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