#!perl use strict; use XML::Twig::XPath; my $xmlfile = $ARGV[0] || 'txlife.xml'; my $twig = XML::Twig::XPath->new(); $twig->parsefile($xmlfile); my $root = $twig->root; my @XPV = (); $XPV[0] = '//Party[@id=//Relation[child::RelationRoleCode[@tc="37"]]/@RelatedObjectID]/Producer/CarrierAppointment/CompanyProducerID'; $XPV[1] = '//OLifE/Party[@id=//OLifE/Relation[RelationRoleCode[@tc=8]]/@RelatedObjectID]/Person/FirstName'; for my $i (0..1){ my ($name,$value) = get_xpath_value($XPV[$i]); print " $name : $value\n"; } sub get_xpath_value { my ($xpath) = @_; my @nodes = $root->findnodes($xpath); my $value = $nodes[0]->text; my $name = $nodes[0]->getName; return ($name,$value); }