Support Questions

Find answers, ask questions, and share your expertise

Convert regular XML file to properties file in nifi?

Explorer

I am trying to convert the following:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<lowToHighFile>
    <alternateDestination>false</alternateDestination>
    <content>MDBiZDRhYTMtZWY2YS00NmFiLWEwMzktZDYyYzAxYzc5YjFl</content>
    <contentType>application/octet-stream</contentType>
    <copyrighted>false</copyrighted>
    <fileHash>81f7d43623f6c03ba4ea0c53e07575739646c710</fileHash>
    <timeStamp>895000000</timeStamp>
    <userName>akpless</userName>
</lowToHighFile>

To:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE properties
SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <entry key="alternateDestination">false</entry>
    <entry key="content">MDBiZDRhYTMtZWY2YS00NmFiLWEwMzktZDYyYzAxYzc5YjFl</entry>
    <entry key="contentType">application/octet-stream</entry>
    <entry key="copyrighted">false</entry>
    <entry key="fileHash">81f7d43623f6c03ba4ea0c53e07575739646c710</entry>
    <entry key="timeStamp">895000000</entry>
    <entry key="userName">akpless</entry>
</properties>

any ideas?

Thank you!!

2 REPLIES 2

You could write an XSLT that transforms your input XML to your output XML, and then use the TransformXML processor to run the XSLT.

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.TransformXml/i...

Explorer

Here's a simple xslt created by @Jayson Ramey

Convert

<?xml version="1.0" encoding="UTF-8"?>
<property>
	<path>./</path>
	<filename>1447519809631049</filename>
	<uuid>ae5f9a71-15fb-4206-92d6-6b7efaacf4b3</uuid>
	<fragment.identifier></fragment.identifier>
</property>

To

<?xml version="1.0" encoding="UTF-8"?>
<property>
	  <entry key="path">./</entry>
	  <entry key="filename">1453076046536069</entry>
	  <entry key="uuid">24957de2-7db4-4d86-b305-746eccf34222</entry>
	  <entry key="fragment.identifier"/>
</property>

By using this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">

    <xsl:template match="node()|@*" name="identity">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="property/*">
        <entry>
                <xsl:attribute name="key" select="name()"/>
                <xsl:apply-templates select="@* | node()"/>
        </entry>
    </xsl:template>
</xsl:stylesheet>
Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.