<!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>Grab all the Error and Warnings out of XML, s/^\n//mg</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>

<P><FONT SIZE=2>Wrote this this morning as a quick proof of some XML tag capture I needed. I<BR>
like the s/^\n//mg trick, which gets rid of the annoying blank lines in<BR>
$in_message scalar.<BR>
<BR>
j<BR>
<BR>
<BR>
<BR>
my $in_message = &lt;&lt;EOT;<BR>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<BR>
<BR>
&lt;OTA_HotelResModifyNotifRQ<BR>
xmlns:xsi=&quot;<A HREF="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A>&quot;<BR>
xsi:schemalocation=&quot;<A HREF="http://www.opentravel.org/OTA/2003/05">http://www.opentravel.org/OTA/2003/05</A><BR>
<A HREF="file:///C:/liaison/Omni">file:///C:/liaison/Omni</A> 1.00/FS_OTA_HotelResModifyNotifRQ.xsd&quot;<BR>
EchoToken=&quot;L00024547MR&quot; TimeStamp=&quot;2007-09-10T08:19:06.986850-05:00&quot;<BR>
Version=&quot;1.003&quot; ResStatus=&quot;Modify&quot;<BR>
xmlns=&quot;<A HREF="http://www.opentravel.org/OTA/2003/05">http://www.opentravel.org/OTA/2003/05</A>&quot;&gt;<BR>
<BR>
&nbsp; &lt;POS&gt;<BR>
<BR>
&nbsp;&nbsp;&nbsp; &lt;Source PseudoCityCode=&quot;AUSCTR&quot; ISOCountry=&quot;US&quot; /&gt;<BR>
<BR>
&nbsp; &lt;/POS&gt;<BR>
<BR>
&nbsp; &lt;HotelResModifies&gt;<BR>
<BR>
&nbsp;&nbsp;&nbsp; &lt;HotelResModify CreateDateTime=&quot;2007-09-10T08:19:06.986850-05:00&quot;<BR>
ResStatus=&quot;In-house&quot;&gt;<BR>
-snip!-<BR>
EOT<BR>
<BR>
my $out_message = &lt;&lt;EOT;<BR>
&lt;OTA_HotelResModifyNotifRS EchoToken=&quot;L00024547MR&quot; ResResponseType=&quot;Ignored&quot;<BR>
TimeStamp=&quot;2007-09-10T08:27:58.53-05:00&quot;&gt;<BR>
&nbsp; &lt;Errors&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;Error Language=&quot;en-us&quot; Type=&quot;3&quot; ShortText=&quot;Invalid arrival time&quot;<BR>
Code=&quot;294&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;/Error&gt;<BR>
&nbsp; &lt;/Errors&gt;<BR>
&lt;/OTA_HotelResModifyNotifRS&gt;<BR>
EOT<BR>
<BR>
my @bad_stuff;<BR>
foreach ($in_message, $out_message) {<BR>
&nbsp;&nbsp; my $twig = new XML::Twig;<BR>
&nbsp;&nbsp; $twig-&gt;parse($_);<BR>
&nbsp;&nbsp; my $root = $twig-&gt;root;<BR>
&nbsp;&nbsp; push @bad_stuff, map { $_-&gt;sprint } $root-&gt;get_xpath('//Error');<BR>
&nbsp;&nbsp; push @bad_stuff, map { $_-&gt;sprint } $root-&gt;get_xpath('//Warning');<BR>
}<BR>
<BR>
print join &quot;\n&quot;, @bad_stuff;<BR>
print &quot;\n&quot;;<BR>
$in_message =~ s/^\n//mg;<BR>
print &quot;$in_message\n&quot;;<BR>
<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>