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

XmlSlurper unprefixed attributes should not be in the default namespace

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.6
    • 2.4.7
    • XML Processing
    • None

    Description

      According to https://www.w3.org/TR/xml-names/#defaulting the namespace name for an unprefixed attribute name always has no value. Currently when using XmlSlurper unprefixed attributes have the default namespace.

      def xml = '''
      <root xmlns="urn:test">
          <foo id="7">bar</foo>
      </root>
      '''
      
      def root = new XmlSlurper(false, true).parseText(xml).declareNamespace(ns: 'urn:test')
      
      assert root.foo[0].namespaceURI() == 'urn:test'
      assert root.'ns:foo'.text() == 'bar'
      
      assert root.foo.@id == '7'
      assert root.foo.'@ns:id' == '' // fails returns 7
      assert root.foo.@id[0].namespaceURI() == '' // fails returns 'urn:test'
      

      Based on the specs I believe the following asserts in the XmlSlurperTest are incorrect.

      Attachments

        Issue Links

          Activity

            People

              jwagenleitner John Wagenleitner
              jwagenleitner John Wagenleitner
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: