#!/usr/bin/perl use strict; use warnings; use XML::Twig; my $t= XML::Twig->new( twig_roots => { 'Collection[@Type="CustomProperty"]' => \&collection}, twig_print_outside_roots => 1, ); $t->parsefile( $ARG[0]); exit; sub collection { my ($t, $collection)= @_; foreach my $sub_record ($collection->children( 'SubRecord')) { my $name = $sub_record->field( 'Property[@Name="Name"]'); my $value = $sub_record->field( 'Property[@Name="Value"]'); # we want to keep thæ attributes (except Name of course) my $atts = $sub_record->first_child( 'Property[@Name="Value"]')->atts; delete $atts->{Name}; my $property= XML::Twig::Elt->new( $name, $atts, $value); $property->replace( $sub_record); } $collection->print; }