Groovy
  1. Groovy
  2. GROOVY-5379

XmlParser trims text between element

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not A Problem
    • Affects Version/s: 1.8.6
    • Fix Version/s: None
    • Component/s: XML Processing
    • Labels:
      None

      Description

      text between elements ending with empty line or white spaces is trimmed. This is the test case that should pass:

      import groovy.xml.*
      def xml = new XmlParser().parseText("<a>x \n\t </a>")
      assert "x \n\t " == xml.text()
      

      Note, that XmlSlurper works fine:

      import groovy.xml.*
      def xml = new XmlSlurper().parseText("<a>x \n\t </a>")
      assert "x \n\t " == xml.text()
      

        Activity

        Jakub Neubauer created issue -
        Hide
        Paul King added a comment -

        For historical reasons, XmlParser defaults to trimming of element text. You probably want:

        import groovy.xml.*
        def a = new XmlParser(trimWhitespace: false).parseText("<a>x \n\t </a>")
        assert "x \n\t " == a.text()
        

        We may change the default in a future version of Groovy.

        Show
        Paul King added a comment - For historical reasons, XmlParser defaults to trimming of element text. You probably want: import groovy.xml.* def a = new XmlParser(trimWhitespace: false ).parseText( "<a>x \n\t </a>" ) assert "x \n\t " == a.text() We may change the default in a future version of Groovy.
        Hide
        Jakub Neubauer added a comment - - edited

        Thanks. Than feel free to close this bug. Any chance to change the defaults in near version? Seems more convenient to me.

        Show
        Jakub Neubauer added a comment - - edited Thanks. Than feel free to close this bug. Any chance to change the defaults in near version? Seems more convenient to me.
        Hide
        Paul King added a comment -

        Russel Winder has just started a debate on this very topic. Please feel free to vote/comment.

        Show
        Paul King added a comment - Russel Winder has just started a debate on this very topic. Please feel free to vote/comment.
        Hide
        Paul King added a comment -

        Currently working as designed.

        Show
        Paul King added a comment - Currently working as designed.
        Paul King made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Paul King [ paulk ]
        Resolution Not A Bug [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12734302 ] Default workflow, editable Closed status [ 12746077 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12971795 ] Default workflow, editable Closed status [ 12979588 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        1d 16h 2m 1 Paul King 25/Mar/12 04:10

          People

          • Assignee:
            Paul King
            Reporter:
            Jakub Neubauer
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development