I'm looking for some suggestion to convert the .asn1 (CDR Data) to CSV to load to tables. As per current approach I'm using informatica B2B parser to parse the ASN file to XML than using XSD loading to Greenplum tables.

I hope Perl can do these operations in a better way; for a day we are receiving a ~30k ASN file which is a very big file.

For converting XML to CSV (Confused about how to convert XML to CSV using xmlstarlet on OS X?) not sure this approach works or if there's any plugin in Perl.

ASN files are binary files, second step is XML to CSV.

Sample XML:

<?xml version="1.0" encoding="windows-1252"?>
<data>connect-progress=Call Up</data>
<eventTimeStamp>140E0A0F 123B0E</eventTimeStamp>

I would like that other than Cisco information rest all also is in CSV.

  • There are proper XML handling libraries for Perl. Problem is that there are unlimited ways to represent tabular data in an XML file. Do you have a representative example for the XML and how it should look as CSV?
    – Anthon
    Nov 15, 2014 at 14:01
  • Please show us an example of your input files and your desired output. Ideally, show us both the ASN and the XML files. I don't see any reason to go through an intermediate XML if what you want is csv. Also, what are CDR data? Remember that we don't work in your field. To me CDR is a Complementarity determining region coding region, are you working with sequences?
    – terdon
    Nov 15, 2014 at 14:22
  • Guys Updated the Question , CDR - Call data records (System generated binary information) mostly in the format of .asn cant be readable by text editor.
    – William R
    Nov 15, 2014 at 14:37
  • There's a comment in this thread: stackoverflow.com/questions/3353004/… that says there is no such tool to convert ASN.1 to CSV. Your Q is still confusing to me. Are you just looking for XML to CSV or something else?
    – slm
    Nov 15, 2014 at 15:04
  • My entire purpose is to convert (asn to csv) step 1: asn1 to xml and step 2 : xml to csv , But if not possible to convert asn to csv lookig for xml to csv conversion in perl.
    – William R
    Nov 15, 2014 at 15:36

2 Answers 2


Don't use XML::Simple. It's a bad idea.

But pretty fundamentally - XML is a hierarchial data structure, CSV isn't. It's impossible to solve a translation for the general case as a result.

However given a standard record structure, it isn't too hard:

#!/usr/bin/env perl

use strict;
use warnings;
use XML::Twig;
use Text::CSV;
use Data::Dumper;

my $twig = XML::Twig->new->parse( \*DATA );

#read heading from first record.
my @headings =
    map { $_->tag } $twig->findnodes( '//accountingRequest', 0 )->children;

my $csv_out = Text::CSV->new( { binary => 1, eol => "\n" } );
$csv_out->print( \*STDOUT, \@headings );

foreach my $accountingRequest ( $twig->findnodes('//accountingRequest') ) {
    my @row = map { $accountingRequest->first_child_text($_) } @headings;
    $csv_out->print( \*STDOUT, \@row );

This extracts the top level 'tag' and then the values that matches them, and prints those.

It isn't perfect though, because as said - your data is hierarchical. You have cisco records, that you need to decide what you want to do with those - how should they be represented in your CSV?


I got the below Code , for different set of XML file to CSV.



# Script to illustrate how to parse a simple XML file
# and pick out all the values for a specific element, in
# this case all the titles.

# use strict;
use XML::Simple;
use Data::Dumper;

# create object
$xml = new XML::Simple (KeyAttr=>[]);

# read XML file
$data = $xml->XMLin("test1.xml");

my $booklist = XMLin('test1.xml');    #booklist is the array 
# print Dumper($booklist);

foreach my $FreemanFees (@{$booklist->{FreemanFees}}) {

    $FreemanFees->{SdcLoanFacilityNumber} , "," , 
    $FreemanFees->{DealId} ,",", 
    $FreemanFees->{Tranche}->{SdcDealNumber} , "," , 
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{ManagerNumberForFreemanFee}, ",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{sdcCurrencyCode} , "," , 
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{scale}, ",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{content} , "," ,"\n" ;

But how to fetch next elements if i have more ?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .