#!/bin/perl -w use strict; use XML::Twig; use Data::Dumper; # generate a file where the content of rec1 and something is # stuck in CDATA sections my $tmp="tmp"; open( TMP, ">$tmp") or die "$0 cannot open $tmp: $!"; while( ) { s{<(rec1|something)>}{<$1>}{]]>}g; print TMP $_; } close TMP; # sorry, I could not help but use XML::Twig for this my %data; my $t= XML::Twig->new( twig_handlers => { r => sub { $data{$_->field( 'key')}= { rec1 => $_->field( 'rec1'), something => $_->field( 'something') }; $_[0]->purge; # I like to save memory } }, ); $t->parsefile( $tmp); print Dumper( %data); __DATA__ k1 data else k2 includes
and non UTF-8 chars like é, or nasties like <
else,

ugly tooisn't it & all