Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4362

Node.text() returns empty string for non-String or Collection values

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.7.4
    • 1.8.6, 2.0-beta-3
    • XML Processing
    • None

    Description

      The text() method of groovy.util.Node is coded to return an empty string ("") if you set a value that is not a string or a collection. This means if you set the value as a number you get back an empty string.

      Should this method return value.toString() in all cases where value is not a collection?

      For instance -

      def xml = "<root><node1/></root>"
      def root = new XmlParser().parseText(xml)
      root.node1[0].replaceNode() {
          node2() {
             childN(5)
             childS('5')
          }
      }
      
      assert root.node2[0].childS[0].text() == '5'
      assert root.node2[0].childN[0].text() == '5'
      

      Attachments

        1. NodeTextNonString.groovy
          0.3 kB
          jspeakman

        Activity

          People

            paulk Paul King
            jspeakman jspeakman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: