Support Questions
Find answers, ask questions, and share your expertise

receive XML and insert to Postgres DB using Nifi

New Contributor

Hello All,

 

I'm trying to create a Nifi flow which performs the below logic:

1- Receive HTTP XML request from External system and send ok response.

2- Process the XML data and extract specific fields form the XML body.

3- Insert the extracted fields to a postgres DB table.

 

below is a sample of the XML body:

<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>XMLRecord</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>MainID</name>
<value>
<string>123456789</string>
</value>
</member>
<member>
<name>origintimestapmp</name>
<value>
<dateTime.iso8601>20211129T14:10:11+0200</dateTime.iso8601>
</value>
</member>
<member>
<name>Xvalue</name>
<value>
<string>5.000000</string>
</value>
</member>
<member>
<name>DataFields</name>
<value>
<struct>
<member>
<name>Action1</name>
<value>
<string />
</value>
</member>
<member>
<name>Acttion2</name>
<value>
<string />
</value>
</member>
<member>
<name>Action3</name>
<value>
<string>Mirror</string>
</value>
</member>
<member>
<name>Action4</name>
<value>
<string>Reactivated</string>
</value>
</member>
</struct>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>

 

the data to be extracted in this format:

MainID,origintimestamp,Xvalue,Action1,Action2,Action3,Action4

sample output:

123456789,20211129T14:10:11+0200,5.000000,,,Mirror,Reactivated

 

and then inserted to the Database table with the same structure.

 

I've managed to achieve the part related to receiving the request and sending the response and connecting to the postgres DB. but I couldn't manage to parse the XML and convert it to database insert format.

 

Thanks a lot for your help in advance,

 

 

0 REPLIES 0