groovy
  1. groovy
  2. GROOVY-5119

Node.depthFirst() 'forgets' text nodes

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8.3
    • Fix Version/s: 2.0-beta-3, 1.8.7
    • Component/s: XML Processing
    • Labels:
      None
    • Environment:
      (any)
    • Number of attachments :
      1

      Description

      Node.depthFirst() is expected to recursively include all Node.children() elements. The attached program demonstrates a counter example, where Node.depthFirst() 'forgets' all 3 text chldren resulting in a list of 4 instead of 7 elements.

      The correct semantics of "Node.depthFirst()" is defined by "depthFirst( node )" in the attached program.

        Activity

        Hide
        Paul King added a comment -

        The behavior of depthFirst and breadthFirst for XmlParser was aligned with XmlSlurper some time back and it intentionally 'forgets' text nodes - just processing elements. I guess we should allow for both behaviors. Certainly depthFirst and breadthFirst need to be kept consistent. The same comments apply to the DOMCategory implementation, i.e. if we make changes we should align its behavior as well.

        Show
        Paul King added a comment - The behavior of depthFirst and breadthFirst for XmlParser was aligned with XmlSlurper some time back and it intentionally 'forgets' text nodes - just processing elements. I guess we should allow for both behaviors. Certainly depthFirst and breadthFirst need to be kept consistent. The same comments apply to the DOMCategory implementation, i.e. if we make changes we should align its behavior as well.
        Hide
        zroh added a comment -

        The Behavior of XmlSlurper.depthFirst() is consistent because XmlSlurper.children() also 'forgets' text children.

        I did not check the behavior of XmlParser.breadthFirst().

        Note that the standard definition of depth and breadth first traversal are based on "node expansion" (using "children()"). Deviations should be explicitely mentioned in the API documentation – if not considered a bug.

        Show
        zroh added a comment - The Behavior of XmlSlurper.depthFirst() is consistent because XmlSlurper.children() also 'forgets' text children. I did not check the behavior of XmlParser.breadthFirst(). Note that the standard definition of depth and breadth first traversal are based on "node expansion" (using "children()"). Deviations should be explicitely mentioned in the API documentation – if not considered a bug.
        Hide
        Paul King added a comment -

        OK, I have a fix for this but am awaiting other discussions regarding further changes to the XML APIs (with regard as to when to trim ignorable whitespace) which might impact my change.

        Show
        Paul King added a comment - OK, I have a fix for this but am awaiting other discussions regarding further changes to the XML APIs (with regard as to when to trim ignorable whitespace) which might impact my change.
        Hide
        Paul King added a comment -

        I went ahead and applied the fix. Depending on on-going discussions about trimming, the output to be expected may be further refined over time for various edge cases.

        Show
        Paul King added a comment - I went ahead and applied the fix. Depending on on-going discussions about trimming, the output to be expected may be further refined over time for various edge cases.
        Paul King made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Paul King [ paulk ]
        Fix Version/s 2.0-beta-3 [ 18244 ]
        Fix Version/s 1.8.7 [ 18317 ]
        Resolution Fixed [ 1 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Paul King
            Reporter:
            zroh
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: