Commons JXPath
  1. Commons JXPath
  2. JXPATH-125

JXPathContext.iteratePointers() does not work with multiple prefixes for a single namespace URI

    Details

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

      JXPath 1.2
      Sun JDK 1.5.0_13

      Description

      Have a look at the following document:

      <a:doc xmlns:a="ns">
      <a:elem />
      <b:elem xmlns:b="ns" />
      </a:doc>

      We have two elements 'elem' in the same namespace 'ns'.
      They have a different prefix, however.

      When we use JXPathContext.iteratePointers() to iterate over them, the first element is returned two times. The second element is not returned.

      This is because
      in class org.apache.commons.jxpath.ri.model.dom.DOMNodePointer
      in method getRelativePositionByName() (line 546)
      we have:

      if (nm.equals(node.getNodeName()))

      In the example, we have
      nm == "a:elem" and node == "b:elem"

      Thus, equals() returns false. But since 'a' and 'b' are just different prefixes for the same namespace URI, we should have 'true'.

      I attached a testcase which reproduces the bug.

        Activity

        Christian Koppen created issue -
        Christian Koppen made changes -
        Field Original Value New Value
        Description I attached a testcase which reproduces the bug.

        Have a look at the following document:

        <a:doc xmlns:a="ns">
          <a:elem />
          <b:elem xmlns:b="ns" />
        </a:doc>

        We have two elements 'elem' in the same namespace 'ns'.
        They have a different prefix, however.
        Have a look at the following document:

        <a:doc xmlns:a="ns">
          <a:elem />
          <b:elem xmlns:b="ns" />
        </a:doc>

        We have two elements 'elem' in the same namespace 'ns'.
        They have a different prefix, however.

        When we use JXPathContext.iteratePointers() to iterate over them, the first element is returned two times. The second element is not returned.

        This is because
        in class org.apache.commons.jxpath.ri.model.dom.DOMNodePointer
        in method getRelativePositionByName() (line 546)
        we have:

        if (nm.equals(node.getNodeName()))

        In the example, we have
        nm == "a:elem" and node == "b:elem"

        Thus, equals() returns false. But since 'a' and 'b' are just different prefixes for the same namespace URI, we should have 'true'.

        I attached a testcase which reproduces the bug.
        Hide
        Christian Koppen added a comment -

        A testcase which reproduces the bug

        Show
        Christian Koppen added a comment - A testcase which reproduces the bug
        Christian Koppen made changes -
        Attachment TestcaseJXPathIterateBug.java [ 12388161 ]
        Christian Koppen made changes -
        Attachment TestcaseJXPathIterateBug.java [ 12388161 ]
        Christian Koppen made changes -
        Attachment TestcaseJXPathIterateBug.java [ 12388162 ]
        Hide
        Christian Koppen added a comment -

        Typo in the summary

        Show
        Christian Koppen added a comment - Typo in the summary
        Christian Koppen made changes -
        Summary JXPathContext.iteratePointers() does not work with multiple prefixes or a single namespace URI JXPathContext.iteratePointers() does not work with multiple prefixes for a single namespace URI
        Hide
        Matt Benson added a comment -

        Please test whether this problem is exhibited with the just-released JXPath 1.3. Thanks!

        Show
        Matt Benson added a comment - Please test whether this problem is exhibited with the just-released JXPath 1.3. Thanks!
        Hide
        Christian Koppen added a comment -

        Problem also occurs in 1.3

        Show
        Christian Koppen added a comment - Problem also occurs in 1.3
        Christian Koppen made changes -
        Affects Version/s 1.3 [ 12312253 ]
        Emmanuel Bourg made changes -
        Fix Version/s post-1.3 [ 12312254 ]
        Hide
        Matt Benson added a comment -

        After much delay...

        Committed revision 917007.

        Thanks!

        Show
        Matt Benson added a comment - After much delay... Committed revision 917007. Thanks!
        Matt Benson made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        563d 3h 44m 1 Matt Benson 27/Feb/10 19:50

          People

          • Assignee:
            Unassigned
            Reporter:
            Christian Koppen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development