in reply to XML parsing question

ug. The problem with XML::Simple is that it doesn't return a consistent format unless you disable everything it considers an advantage. It's no longer using XML::LibXML, and it's much faster.

For good measure, I used Text::CSV_XS for output.

use strict; use warnings; use Text::CSV_XS qw( ); use XML::LibXML qw( ); my $csv = Text::CSV_XS->new({ binary => 1, eol => $/ }); my $parser = XML::LibXML->new(); my $doc = $parser->parse_file('infile.xml'); my $root = $doc->documentElement(); for my $doc_node ( $root->findnodes('/results/document') ) { my @doc_fields = map $doc_node->getAttribute($_), qw( datetime id sourcecategory schemeversion ); my @rec_nodes = $doc_node->findnodes('record'); if (!@rec_nodes) { $csv->print(*STDOUT, \@doc_fields); next; } for my $rec_node ( @rec_nodes ) { $csv->print(*STDOUT, [ @doc_fields, map $rec_node->findvalue("$_/text()"), qw( sentence-number data-class group ) ]); } }