groovy
  1. groovy
  2. GROOVY-5379

XmlParser trims text between element

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Not A Bug
    • Affects Version/s: 1.8.6
    • Fix Version/s: None
    • Component/s: XML Processing
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      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

        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.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: