#!/usr/bin/env perl use strict; use warnings; use XML::Twig; ################################################# ################################################# my $twig_show_messages = new XML::Twig( twig_handlers => # message will be called { message => \&print_all_messages_id_desc } # when each message element ); # has been parsed $twig_show_messages->parsefile("sip2_params_client_small.xml"); # build the twig #### $twig_show_messages->flush; ######################################## ######################################## print "Your SIP2 message ID?>_\t"; my $match_msg=''; chomp ($match_msg=<> ); ## Check the input if ($match_msg !~ /^(-)*\d{2}$/){ ## Input must be 2 digits! If not... exit! print "***===>>>input $match_msg. \n"; print "\tIt is not numeric, or does *not* contain two digit\n"; exit; } ######################################## ######################################## my $twig_for_a_message= new XML::Twig(); ######################################## ######################################## my $twig_the_selected_message= new XML::Twig( twig_handlers => { doc => \&doc, section => \§ion, } ); ######################################## ######################################## &print_chosen_msg; ################################################# ################################################# ################################################# ################################################# ################################################# ################################################# sub print_all_messages_id_desc { my( $twig, $message)= @_; # handlers params are always # the twig and the element my $message_id = $message->first_child('message_id')->text; # get the text of message_id my $message_desc = $message->first_child('message_desc')->text; # get the text of message_desc print "$message_id\t$message_desc\n"; # print message id and desc } ################################################# ################################################# sub print_chosen_msg { my $sw_msg_flag= ' '; print "You chose:\t"; ### START XML::Twig XML::Twig->new( twig_handlers => { ## START message_id message_id => sub { if ($_->text eq $match_msg) { print $_->text ; print "\t"; $sw_msg_flag='Y'; } ## END IF }, ## END message_id message_desc => sub { if ($sw_msg_flag eq 'Y') { print "\n"; print $_->text ; print "\n"; $sw_msg_flag='N'; # exit; } ## END IF } ## END message_desc } ## END twig_handlers )->parsefile('sip2_params_client.xml'); ### END XML::Twig print "\t==============================\n"; } #### 23 Patron Status Request language 3-char, fixed-length required field transaction date 18-char, fixed-length required field: YYYYMMDDZZZZHHMMSS institution id AO variable-length required field patron identifier AA variable-length required field terminal password AC variable-length required field patron password AD variable-length required field 09 Checkin no block 1-char, fixed-length required field: Y or N. transaction date 18-char, fixed-length required field: YYYYMMDDZZZZHHMMSS return date 18-char, fixed-length required field: YYYYMMDDZZZZHHMMSS current location AP variable-length required field