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

XmlSlurper does not maintain a stack of prefix mappings

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.8.7, 2.0.4, 2.0.6
    • None
    • XML Processing
    • None

    Description

      As a result methods that rely on the mapping (e.g. XmlSlurper#lookupNamespace(String)) do not work correctly:

      def xml = new XmlSlurper(false, true).parseText('''<root xmlns:tns="urn:first">
        <tns:a tns:attr="value"/>
        <tns:b xmlns:tns="urn:second" attr="value"/>
        <tns:c attr="value"/>
      </root>''');
      
      xml.declareNamespace(ns1:'urn:first', ns2:'urn:second')
      
      assert xml.'ns1:a'[0].namespaceURI() == "urn:first"  // OK
      assert xml.'ns2:b'[0].namespaceURI() == "urn:second" // OK
      assert xml.'ns1:c'[0].namespaceURI() == "urn:first"  // OK
      
      assert xml.'ns1:a'[0].lookupNamespace("tns") == "urn:first"   // ERROR
      assert xml.'ns2:b'[0].lookupNamespace("tns") == "urn:second"  // OK
      assert xml.'ns1:c'[0].lookupNamespace("tns") == "urn:first"   // ERROR
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            veita Alexander Veit
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: