#! /usr/bin/perl use strict; use XML::Twig; my $gobjXML; my $ghshAvail = {}; eval { $gobjXML = XML::Twig->new( twig_handlers => { availability_messages => \&xxx } ); $gobjXML->parsefile("test.xml"); $gobjXML->purge(); $gobjXML->dispose(); undef($gobjXML); }; sub xxx { my($objt,$objnode) = @_; my $exp = qq(./message[\@id]); foreach my $node ($objnode->get_xpath($exp)) { if( ! defined($ghshAvail->{$node->{att}->{'id'}})) { $ghshAvail->{$node->{att}->{'id'}} = $node->text(); } print "The attrib is " . $node->{att}->{"id"} . " the value is " . $node->text() . "\n"; } } #### out of stock and will
ship in approximately
1 - 2 weeks. learn more]]>
in stock. *]]> out of stock and will
ship in approximately
2 - 4 weeks. learn more]]>
from the manufacturer and will
ship in approximately 4 - 6 weeks.
learn more]]>