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

XMLSlurper accessing xml:id

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6, 2.1.6, 2.2.0-beta-1
    • 2.3.0-rc-1
    • XML Processing
    • None

    Description

      I believe I have found a regression introduced by GROOVY-4637 The issue is most easily demonstrated through the following tests:

      import spock.lang.*
      
      class XmlSlurperPasivityTest extends Specification {
        def theInputData = '''<?xml version="1.0" encoding="UTF-8"?>
                  <appendix version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xml="http://www.w3.org/XML/1998/namespace"> 
                    <section xml:id="a"/> 
                  </appendix>'''
      
        def theXml = new XmlSlurper().parseText(theInputData)
            .declareNamespace(xml:'http://www.w3.org/XML/1998/namespace', docbook: 'http://docbook.org/ns/docbook')
      
        def 'attributes().get("id")'() {
          when:
            def id = theXml.section[0].attributes().get('id')
          then: 'failure with >= groovy 1.6 and success with < groovy 1.6'
            id == 'a'
        }
      
        def '.@id'() {
          when:
            def id = theXml.section[0].@'id'
          then: 'failure with >= groovy 1.6 and success with < groovy 1.6'
            id == 'a'
        }
      
        def '.@"xml:id"'() {
          when:
            def id = theXml.section[0].@'xml:id'
          then: 'failure with >= groovy 1.6 and success with < groovy 1.6'
            id == 'a'
        }
        
        def 'attributes().get()'() {
          when:
            def id = theXml.section[0].attributes().get('{http://www.w3.org/XML/1998/namespace}id')
          then: 'success with >= groovy-1.6'
            id == 'a'
        }
      
        def 'attributes().get("xml:id")'() {
          when:
            def id = theXml.section[0].attributes().get('xml:id')
          then: 'failure with all'
            id == 'a'
        }
      }
      

      Attachments

        Activity

          People

            paulk Paul King
            rwinch Robert Winch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: