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

XmlParser wraps nested elements in extra ArrayList

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 1.6.7
    • 1.6.8, 1.7.1
    • None
    • None
    • Grails 1.2, Groovy 1.6.7

    Description

      When using XmlParser we are experienceing different behaviour within Grails 1.2 than directly using Groovy 1.6.7. The issue manifests itself when accessing nested elements in a document.

      example, this works fine from within GroovyConsole 1.6.7:

      def XML = '''<channel>
        <item id="1"/>
        <item id="2"/>
        <item id="3"/>
      </channel>'''
      assert 3 == new XmlParser().parseText(XML).item.size()
      assert 3 == new XmlParser().parseText("<rss>$XML</rss>").channel.item.size()
      

      Here is a test case that passed under Grails 1.1.1 but fails under 1.2:

      class XMLUnitTests extends GroovyTestCase {
          def XML = '''
              <channel>
                <item id="1"/>
                <item id="2"/>
                <item id="3"/>
              </channel>
          '''
      
          void testOneLevel() {
              def records = new XmlParser().parseText(XML)
              assertEquals 3, records.item.size()
          }
      
          void testTwoLevels() {
              def records = new XmlParser().parseText("<rss>$XML</rss>")
              assertEquals 3, records.channel.item.size()
          }
      }
      

      Attachments

        1. xmlparserissue-bug-report-27012010.zip
          19 kB
          Guillaume Sauthier

        Activity

          People

            blackdrag Jochen Theodorou
            james.cookie James Cook
            Votes:
            6 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: