nifi-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sally <sally.tkhilaishv...@gmail.com>
Subject Groovy:remove all namespace from xml
Date Wed, 15 Nov 2017 10:33:05 GMT
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/

Mime
View raw message