<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Attributes to XML (not JSON) in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159334#M57159</link>
    <description>&lt;P&gt;Yes it is possible with ExecuteScript if nothing else.  Try the following Groovy script in your ExecuteScript processor:&lt;/P&gt;&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return
class WriteCallback implements OutputStreamCallback {
  Map attrs
  WriteCallback(attributes) {
    attrs = attributes
  }
  void process(OutputStream outputStream) {
    outputStream.write('&amp;lt;root&amp;gt;\n'.bytes)
    attrs.each {k,v -&amp;gt; 
      outputStream.write("&amp;lt;property&amp;gt;\n\t&amp;lt;name&amp;gt;$k&amp;lt;/name&amp;gt;\n\t&amp;lt;value&amp;gt;$v&amp;lt;/value&amp;gt;\n".bytes)
    }
    outputStream.write('&amp;lt;/root&amp;gt;'.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)&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 06:38:36 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2017-03-16T06:38:36Z</dc:date>
    <item>
      <title>Attributes to XML (not JSON)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159333#M57158</link>
      <description>&lt;P&gt;Im looking for a way to get attributes in an XML file instead of json. The current proccesor only does attributes to json. &lt;/P&gt;&lt;P&gt;Any ideas? Maybe using an execute script proccesor? Lua code?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 02:27:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159333#M57158</guid>
      <dc:creator>johnmteabo</dc:creator>
      <dc:date>2017-03-16T02:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes to XML (not JSON)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159334#M57159</link>
      <description>&lt;P&gt;Yes it is possible with ExecuteScript if nothing else.  Try the following Groovy script in your ExecuteScript processor:&lt;/P&gt;&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return
class WriteCallback implements OutputStreamCallback {
  Map attrs
  WriteCallback(attributes) {
    attrs = attributes
  }
  void process(OutputStream outputStream) {
    outputStream.write('&amp;lt;root&amp;gt;\n'.bytes)
    attrs.each {k,v -&amp;gt; 
      outputStream.write("&amp;lt;property&amp;gt;\n\t&amp;lt;name&amp;gt;$k&amp;lt;/name&amp;gt;\n\t&amp;lt;value&amp;gt;$v&amp;lt;/value&amp;gt;\n".bytes)
    }
    outputStream.write('&amp;lt;/root&amp;gt;'.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)&lt;/PRE&gt;&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 06:38:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159334#M57159</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-03-16T06:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Attributes to XML (not JSON)</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159335#M57160</link>
      <description>&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 21:40:39 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Attributes-to-XML-not-JSON/m-p/159335#M57160</guid>
      <dc:creator>akp4tibco</dc:creator>
      <dc:date>2017-05-05T21:40:39Z</dc:date>
    </item>
  </channel>
</rss>

