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

XmlSlurper does not maintain a stack of prefix mappings

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.8.7, 2.0.4, 2.0.6
    • Fix Version/s: None
    • Component/s: XML Processing
    • Labels:
      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

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

              Dates

              • Created:
                Updated: