#!/bin/perl -w

#########################################################################
#                                                                       #
#  This example shows how to use the start_tag_handlers option          #
#  It changes all tag names                                             #
#                                                                       #
#########################################################################

use strict;
use XML::Twig;

# the old_tag => new_tag table
my %change=
  ( stats => 'statistics',
    g     => 'games',
    ppg   => 'points_per_game',
    rpg   => 'rebounds_per_games',
    apg   => 'assists_per_games',
    blk   => 'blocks',
  );

# let's build the start_tag_handlers
my $handlers;
while( my( $old_tag, $new_tag)= each( %change) )                    # each handler
  { $handlers->{$old_tag}= sub { $_[1]->set_gi( $new_tag); }; }     # changes a tag


my $twig= new XML::Twig( start_tag_handlers => $handlers,
                         twig_handlers      => 
                             { '_all_' => sub { $_[0]->flush; } },  # flush all elements
                       ); 

$twig->parsefile( "nba.xml");    # process the twig

