<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>XML::Twig, get_xpath are cool</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<P><FONT SIZE=2>The fact that you can hop up to your parent element with ../ in xpath is just way too cool. :)<BR>
<BR>
j<BR>
<BR>
<BR>
<BR>
$ cat j.pl<BR>
use XML::Twig;<BR>
my $xml = grab_xml();<BR>
my $twig = XML::Twig->new();<BR>
$twig->parse($xml);<BR>
my $root = $twig->root;<BR>
foreach my $i ($root->get_xpath('Inventories/Inventory/StatusApplicationControl')) {<BR>
print $i->{att}->{InvType};<BR>
foreach my $j ($i->get_xpath('../InvCounts/InvCount')) {<BR>
print " " . $j->{att}->{Count};<BR>
}<BR>
print "\n";<BR>
}<BR>
<BR>
sub grab_xml {<BR>
return <<EOT;<BR>
<OTA_HotelInvCountNotifRS><BR>
<Inventories><BR>
<Inventory><BR>
<StatusApplicationControl InvType="RODG" Start="2007-07-28" End="2007-07-28"><BR>
</StatusApplicationControl><BR>
<InvCounts><BR>
<InvCount Count="-2"><BR>
</InvCount><BR>
</InvCounts><BR>
</Inventory><BR>
<Inventory><BR>
<StatusApplicationControl InvType="KNSUP" Start="2007-07-28" End="2007-07-28"><BR>
</StatusApplicationControl><BR>
<InvCounts><BR>
<InvCount Count="-95"><BR>
</InvCount><BR>
</InvCounts><BR>
</Inventory><BR>
<Inventory><BR>
<StatusApplicationControl InvType="THOR" Start="2007-07-28" End="2007-07-28"><BR>
</StatusApplicationControl><BR>
<InvCounts><BR>
<InvCount Count="1000"><BR>
</InvCount><BR>
</InvCounts><BR>
</Inventory><BR>
</Inventories><BR>
<Success></Success><BR>
</OTA_HotelInvCountNotifRS><BR>
EOT<BR>
}<BR>
<BR>
$ perl j.pl<BR>
RODG -2<BR>
KNSUP -95<BR>
THOR 1000<BR>
</FONT>
</P>
</BODY>
</HTML>