#!/bin/perl -w

#########################################################################
#                                                                       #
#  This example displays whether an element appears before another one  #
#  in the document                                                      #
#  It uses the elt_id method, by default the id attribute will be 'id'  #
#                                                                       #
#########################################################################

use strict;
use XML::Twig;

my $id1= "player" . shift;
my $id2= "player" . shift;

my $twig= new XML::Twig();

if( $ARGV[0]) { $twig->parsefile( $ARGV[0]); }        # parse a file
else          { $twig->parse( \*STDIN);      }        # parse the standard input

my $player1= $twig->elt_id( $id1);                    # get the players
my $player2= $twig->elt_id( $id2);                     

my $name1= $player1->first_child( 'name')->text;
my $name2= $player2->first_child( 'name')->text;

if( $player1->before( $player2) )
  { printf "$name1 is before $name2\n" }
elsif( $player1->after( $player2) )
  { printf "$name1 is after $name2\n" }
else
  { printf "$name1 is equal to $name2\n" }

