Commons JXPath
  1. Commons JXPath
  2. JXPATH-109

Namespaced attribute not selected with wildcard

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.3
    • Labels:
      None
    • Environment:

      ALL

      Description

      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; }

        Activity

        Matt Benson made changes -
        Field Original Value New Value
        Fix Version/s Nightly Builds [ 12311823 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 1.3 [ 12312253 ]
        Hide
        Matt Benson added a comment -

        fixed; rev 617940

        Show
        Matt Benson added a comment - fixed; rev 617940
        Hide
        Michele Vivoda added a comment -

        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.

        Show
        Michele Vivoda added a comment - 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.
        Michele Vivoda created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Michele Vivoda
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development