Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 03-15-2017 07:27 PM
Im looking for a way to get attributes in an XML file instead of json. The current proccesor only does attributes to json.
Any ideas? Maybe using an execute script proccesor? Lua code?
Thank you!
Created 03-15-2017 11:38 PM
Yes it is possible with ExecuteScript if nothing else. Try the following Groovy script in your ExecuteScript processor:
def flowFile = session.get()
if(!flowFile) return
class WriteCallback implements OutputStreamCallback {
Map attrs
WriteCallback(attributes) {
attrs = attributes
}
void process(OutputStream outputStream) {
outputStream.write('<root>\n'.bytes)
attrs.each {k,v ->
outputStream.write("<property>\n\t<name>$k</name>\n\t<value>$v</value>\n".bytes)
}
outputStream.write('</root>'.bytes)
}
}
def wb = new WriteCallback(flowFile.attributes)
flowFile = session.write(flowFile, wb)
flowFile = session.putAttribute(flowFile, org.apache.nifi.flowfile.attributes.CoreAttributes.MIME_TYPE.key(), 'application/xml')
session.transfer(flowFile, REL_SUCCESS)This should pretty-print your attributes in a "properties-style" XML format. Of course you can edit the script to give you the schema you like.
Created 03-15-2017 11:38 PM
Yes it is possible with ExecuteScript if nothing else. Try the following Groovy script in your ExecuteScript processor:
def flowFile = session.get()
if(!flowFile) return
class WriteCallback implements OutputStreamCallback {
Map attrs
WriteCallback(attributes) {
attrs = attributes
}
void process(OutputStream outputStream) {
outputStream.write('<root>\n'.bytes)
attrs.each {k,v ->
outputStream.write("<property>\n\t<name>$k</name>\n\t<value>$v</value>\n".bytes)
}
outputStream.write('</root>'.bytes)
}
}
def wb = new WriteCallback(flowFile.attributes)
flowFile = session.write(flowFile, wb)
flowFile = session.putAttribute(flowFile, org.apache.nifi.flowfile.attributes.CoreAttributes.MIME_TYPE.key(), 'application/xml')
session.transfer(flowFile, REL_SUCCESS)This should pretty-print your attributes in a "properties-style" XML format. Of course you can edit the script to give you the schema you like.
Created 05-05-2017 02:40 PM
I am looking for a way to convert DB Query reusult set to XML and XML to SQL and also JSON to XML. Is this doable?