Groovy
  1. Groovy
  2. GROOVY-7808

XmlSlurper unprefixed attributes should not be in the default namespace

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: XML Processing
    • Labels:
      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.

        Issue Links

          Activity

          Hide
          John Wagenleitner added a comment -

          Fix for this is included in fix for GROOVY-7781 in GitHub PR 302.

          Show
          John Wagenleitner added a comment - Fix for this is included in fix for GROOVY-7781 in GitHub PR 302 .

            People

            • Assignee:
              John Wagenleitner
              Reporter:
              John Wagenleitner
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development