fork download
  1. def xmlString = """ <soapenv:Envelope xmlns:soapenv="http://s...content-available-to-author-only...p.org/soap/envelope/" xmlns:ns="nsurl"> <soapenv:Header/> <soapenv:Body> <ns:GetRequest> <ns:Identifier>Type="x" Value="y"</ns:Identifier> </ns:GetRequest> </soapenv:Body> </soapenv:Envelope>"""
  2. def xml = new XmlSlurper().parseText(xmlString)
  3. def identifier = xml.'**'.find{it.name() == 'Identifier'}
  4. def map = identifier.text().split(' ').collectEntries{ [(it.split('=')[0]) : it.split('=')[1].replace('"','')]}
  5. identifier.replaceBody { '' }
  6. map.each{k,v -> identifier.@"$k" = v}
  7. println groovy.xml.XmlUtil.serialize(xml)
Success #stdin #stdout 1.25s 4456448KB
stdin
Standard input is empty
stdout
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://s...content-available-to-author-only...p.org/soap/envelope/">
  <soapenv:Header/>
  <soapenv:Body>
    <ns:GetRequest xmlns:ns="nsurl">
      <ns:Identifier Type="x" Value="y"/>
    </ns:GetRequest>
  </soapenv:Body>
</soapenv:Envelope>