You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Michele Vivoda (JIRA)" <ji...@apache.org> on 2007/12/21 02:06:43 UTC

[jira] Commented: (JXPATH-109) Namespaced attribute not selected with wildcard

    [ https://issues.apache.org/jira/browse/JXPATH-109?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12553837 ] 

Michele Vivoda commented on JXPATH-109:
---------------------------------------

Making the change as suggeste breaks one test, that in my opinion is wrong.

Line 543 of XMLModelTestCase

        // attribute:: with default namespace and wildcard
        assertXPathValueIterator(
            context,
            "vendor/product/price:amount/@*",
            list("20%"));

A wildcard attribute selects all the attributes with or without a namespace, 
and not as is written, attributes with default namespace.

So I believe it should be changed to :

        // attribute:: with no namespace
        assertXPathValueIterator(
            context,
            "vendor/product/price:amount/@*[namespace-uri()='']",
            list("20%"));

       // attribute::  all
        assertXPathValueIterator(
            context,
            "vendor/product/price:amount/@*",
            set("10%", "20%"));

must also add to JXPathTestCase:

protected static Set set(Object o1, Object o2) {
        Set list = new HashSet();
        list.add(o1);
        list.add(o2);
        return list;
    }

Running the test I noticed also JDOM model is affected by the same problem,
so at line 82 of JDOMAttributeIterator:

if (attr.getNamespace().equals(ns)) {
                        attributes.add(attr);
}

should become:

if (prefix==null || attr.getNamespace().equals(ns)) {
                        attributes.add(attr);
}

With this last change tests run ok.

> Namespaced attribute not selected with wildcard
> -----------------------------------------------
>
>                 Key: JXPATH-109
>                 URL: https://issues.apache.org/jira/browse/JXPATH-109
>             Project: Commons JXPath
>          Issue Type: Bug
>         Environment: ALL
>            Reporter: Michele Vivoda
>             Fix For: Nightly Builds
>
>
> With expression:
> xml/@*
> On xml:
> <xml xmlns:x='foo' x:pop='a'/>
> selectSingleNode returns null, @x:* works fine.
> Possible Fix:
> In DOMAttributeIterator, line 84
> if (equalStrings(testPrefix, nodePrefix)) {
>                 return true;
>             }
> should probably be changed to
> if (testPrefix==null || equalStrings(testPrefix, nodePrefix)) {
>                 return true;
>             }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.