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

XmlSlurper GPathResult may contain erroneous null elements at end of findAll lists

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-RC-1
    • 1.0-RC-1
    • XML Processing
    • None

    Description

      def doc = """
      <agora-collection name="docstrct">
      	<element-list>
      		<element name="18PP-ParlReg2" root="yes" >
              	    <name xml:lang="en">Item 1</name>
      	        </element>
      	
      		<element name="18PP-HPHC" root="yes" >
      	            <name xml:lang="en">Item 2</name>
              	</element>
      		<element name="Something else" root="yes" >
                  <name xml:lang="en">Item 3</name>
             	</element>
      	</element-list>
      </agora-collection>
      """
      
      docstruct = new XmlSlurper().parseText( doc)
      
      all18PPTopLevelElements = docstruct['element-list'].element.findAll() {
      	it.@name.text().startsWith('18PP-') && (it.@name.text().count('-') == 1)
      }
      
      all18PPTopLevelElements.each() { println it }
      

      This outputs:
      ========
      Item 1
      Item 2
      null
      ========

      Attachments

        Activity

          People

            tug John Wilson
            marc@anyware.co.uk Marc Palmer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: