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

xml:lang attribute appears to break StreamingMarkupBuilder >= 2.0.6

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6, 2.1.0-beta-1
    • 2.1.0-rc-1, 2.0.7
    • XML Processing
    • None
    • java version "1.7.0_09"
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
      Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

    Description

      When using XmlSlurper to parse XML containing an xml:lang attribute and trying to write out this XML using StreamingMarkupBuilder, I get this error in 2.0.6 and 2.1.0-beta-1, which I didn't get in 2.0.5:

      [Fatal Error] :1:19: Attribute name "xml:" associated with an element type "tag0:grammar" must be followed by the ' = ' character.
      ERROR:  'Attribute name "xml:" associated with an element type "tag0:grammar" must be followed by the ' = ' character.'
      Caught: groovy.lang.GroovyRuntimeException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 19; Attribute name "xml:" associated with an element type "tag0:grammar" must be followed by the ' = ' character.
      groovy.lang.GroovyRuntimeException: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 19; Attribute name "xml:" associated with an element type "tag0:grammar" must be followed by the ' = ' character.
      	at broken-groovy-test$_run_closure2.doCall(broken-groovy-test.groovy:8)
      	at broken-groovy-test.run(broken-groovy-test.groovy:8)
      

      The groovy code in question is:

      import groovy.xml.StreamingMarkupBuilder;
      import groovy.xml.XmlUtil;
      
      def grammar = new XmlSlurper().parse(new File(args[0]))
      def builder = new StreamingMarkupBuilder()
      def copier = builder.bind { mkp.yield(grammar) };
      processedFile = new File("test-out.xml")
      processedFile.withWriter{ it << XmlUtil.serialize(copier) } 
      

      And the XML that makes it fail is:

      <?xml version="1.0" encoding="UTF-8"?>
      <grammar xml:lang="en-us" xmlns="http://www.w3.org/2001/06/grammar">
      </grammar>
      

      Attachments

        Activity

          People

            paulk Paul King
            dhdaines David Huggins Daines
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: