web stats
XML to CSV - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2017, 05:37 AM
yeruva yeruva is offline
Mirth Newb
 
Join Date: Nov 2017
Location: Dallas, USA
Posts: 24
yeruva is on a distinguished road
Default XML to CSV

Can someone suggest how to convert XML to CSV using mirth connector 3.6.1

Last edited by yeruva; 09-14-2018 at 04:51 AM.
Reply With Quote
  #2  
Old 12-26-2017, 06:40 AM
appsbyaaron's Avatar
appsbyaaron appsbyaaron is offline
Mirth Guru
 
Join Date: Nov 2011
Location: Florida, USA
Posts: 377
appsbyaaron is on a distinguished road
Default

Did you try something like this?

http://www.mirthcorp.com/community/f...hlight=xml+csv

var finalCSV="";
var len=msg.children().length();
var i=1;

for each(csv in msg.children())
{
if(i<len)
finalCSV+=csv + ",";
else
finalCSV+=csv;

i++;
}

channelMap.put("CSV", finalCSV);
Reply With Quote
  #3  
Old 09-14-2018, 04:50 AM
yeruva yeruva is offline
Mirth Newb
 
Join Date: Nov 2017
Location: Dallas, USA
Posts: 24
yeruva is on a distinguished road
Default

Its not working. any other alternate solution?
Reply With Quote
  #4  
Old 09-14-2018, 09:06 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

For this question and your XML to JSON question, you probably just want to use the inbound and outbound templates and create drag-and-drop message builder steps. If provided suggestions don't work for you, you'll have to provide a lot more information if you expect any meaningful help.

In another thread I recommended you download and explore the User Guide. Have you done this?

Please read the announcement thread about posting to this forum. https://www.mirthcorp.com/community/...nt.php?f=6&a=2
Reply With Quote
  #5  
Old 09-16-2018, 06:51 PM
yeruva yeruva is offline
Mirth Newb
 
Join Date: Nov 2017
Location: Dallas, USA
Posts: 24
yeruva is on a distinguished road
Default

@Angermano
I'm trying to convert attached XML to delimited text by providing channel reader in source tab and save it in CSV file by providing File Writer in destinations tab.

yae, i'm also going through user guide. But not able to resolve it. It would be really helpful if you can help me on this.
Attached Files
File Type: xml XML to CSV example.xml (53.3 KB, 14 views)
Reply With Quote
  #6  
Old 09-17-2018, 02:53 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 95
amble is on a distinguished road
Default

this work? I've not done this before but seems like this is what you want?
Attached Files
File Type: xml XML to CSV example.xml (18.8 KB, 27 views)
Reply With Quote
  #7  
Old 09-17-2018, 03:54 AM
yeruva yeruva is offline
Mirth Newb
 
Join Date: Nov 2017
Location: Dallas, USA
Posts: 24
yeruva is on a distinguished road
Default

Thanks Amble for your help. It's working. But XML format is not constant. I'm trying to convert any XML format into CSV.
Reply With Quote
  #8  
Old 09-17-2018, 04:36 AM
amble amble is offline
OBX.2 Kenobi
 
Join Date: Nov 2015
Posts: 95
amble is on a distinguished road
Default

Maybe try this instead then - not sure if you can expect to cater for every variance of xml though, maybe just root.
Attached Files
File Type: xml XML to CSV example.xml (16.0 KB, 44 views)
Reply With Quote
  #9  
Old 09-17-2018, 08:20 AM
yeruva yeruva is offline
Mirth Newb
 
Join Date: Nov 2017
Location: Dallas, USA
Posts: 24
yeruva is on a distinguished road
Default

@amble Thanks a lot for the reply! its working for single tag how to read nested tags. i have the belwo example, i would like to convert to csv.
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="CDA.xsl"?>
<First>
<Second>
<id ext="12345" rt="2"/>
<addr>
<STADD>17th cross</STADD>
</addr>
<ph value="55-1212" use="PH"/>
<Pname>
<name>
<given>Girish</given>
</name>
<gender code="M" cs="2"/>
<birthTime value="19541125"/>
<guardian>
<id extension="23456" root="2.16.840.1.113883.19.5"/>
<addr>
<STADD>17 Daws Rd.</STADD>
<city>Blue Bell</city>
</addr>
<ph value="2004" use="PH"/>
<gPerson>
<name>
<given>Ralph</given>
</name>
</gPerson>
</guardian>
</Pname>
<providerOrganization>
<id rt="2"/>
<name>Good</name>
<ph value="1212" use="WP"/>
<addr>
<STADD>2 Ave</STADD>
</addr>
</providerOrganization>
</Second>
</First>

Last edited by yeruva; 09-18-2018 at 09:18 AM.
Reply With Quote
  #10  
Old 09-17-2018, 11:12 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,176
agermano is on a distinguished road
Default

What do you expect the output csv to look like? The xml structure is a tree, and csv is a list. There are a number of ways to do it and get different results.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation