<!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.&nbsp; :)<BR>
<BR>
j<BR>
<BR>
<BR>
<BR>
$ cat j.pl<BR>
use XML::Twig;<BR>
my $xml = grab_xml();<BR>
my $twig = XML::Twig-&gt;new();<BR>
$twig-&gt;parse($xml);<BR>
my $root = $twig-&gt;root;<BR>
foreach my $i ($root-&gt;get_xpath('Inventories/Inventory/StatusApplicationControl')) {<BR>
&nbsp;&nbsp; print $i-&gt;{att}-&gt;{InvType};<BR>
&nbsp;&nbsp; foreach my $j ($i-&gt;get_xpath('../InvCounts/InvCount')) {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot; &quot; . $j-&gt;{att}-&gt;{Count};<BR>
&nbsp;&nbsp; }<BR>
&nbsp;&nbsp; print &quot;\n&quot;;<BR>
}<BR>
<BR>
sub grab_xml {<BR>
&nbsp;&nbsp; return &lt;&lt;EOT;<BR>
&lt;OTA_HotelInvCountNotifRS&gt;<BR>
&nbsp; &lt;Inventories&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;Inventory&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StatusApplicationControl InvType=&quot;RODG&quot; Start=&quot;2007-07-28&quot; End=&quot;2007-07-28&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/StatusApplicationControl&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;InvCounts&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;InvCount Count=&quot;-2&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/InvCount&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/InvCounts&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;/Inventory&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;Inventory&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StatusApplicationControl InvType=&quot;KNSUP&quot; Start=&quot;2007-07-28&quot; End=&quot;2007-07-28&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/StatusApplicationControl&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;InvCounts&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;InvCount Count=&quot;-95&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/InvCount&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/InvCounts&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;/Inventory&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;Inventory&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StatusApplicationControl InvType=&quot;THOR&quot; Start=&quot;2007-07-28&quot; End=&quot;2007-07-28&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/StatusApplicationControl&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;InvCounts&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;InvCount Count=&quot;1000&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/InvCount&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/InvCounts&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;/Inventory&gt;<BR>
&nbsp; &lt;/Inventories&gt;<BR>
&nbsp; &lt;Success&gt;&lt;/Success&gt;<BR>
&lt;/OTA_HotelInvCountNotifRS&gt;<BR>
EOT<BR>
}<BR>
<BR>
$ perl j.pl<BR>
RODG -2<BR>
KNSUP -95<BR>
THOR 1000<BR>
</FONT>
</P>

</BODY>
</HTML>