Try this:

def slurper = new XmlSlurper()
def clean   = [:]
def parsed = slurper.parseText(inputString)
clean.putAll(parsed)

//Serialize to XML w/ preferred API

On Wed, Nov 15, 2017 at 5:33 AM, sally <sally.tkhilaishvili@gmail.com> wrote:
I want to romeve namespaces from my xml response(now i am working inside nifi
environment,so i have to use groovy utilities) here is my code , but it
throws FlowfFileHandlingException, what should i change to make this code
work?:


import org.apache.commons.io.IOUtils
import java.nio.charset.StandardCharsets
import groovy.lang.*
import java.util.concurrent.TimeUnit;
import java.lang.String;
import groovy.xml.XmlUtil



def flowFile=session.get();
 String removeXmlStringNamespaceAndPreamble(String xmlString) {
  return xmlString.replaceAll("(<\\?[^<]*\\?>)?", "").
  replaceAll("xmlns.*?(\"|\').*?(\"|\')", "")
  .replaceAll("(<)(\\w+:)(.*?>)", "${1}${3}")
  .replaceAll("(</)(\\w+:)(.*?>)", "${1}${3}");
  }

 def text = ''
   session.read(flowFile, {inputStream ->
   text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
   } as InputStreamCallback)

//text=removeXmlStringNamespaceAndPreamble(text);
log.error(removeXmlStringNamespaceAndPreamble(text));
  def root = new XmlSlurper( false, false ).parse( text );
  String outxml = groovy.xml.XmlUtil.serialize( root );
    flowFile = session.write(flowFile, {outputStream ->
   outputStream.write(outxml.getBytes(StandardCharsets.UTF_8))
   }  as OutputStreamCallback)
session.transfer(flowFile,REL_SUCCESS);



--
Sent from: http://apache-nifi-users-list.2361937.n4.nabble.com/