<!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 = <<EOT;<BR>
<?xml version="1.0" encoding="utf-8"?><BR>
<BR>
<OTA_HotelResModifyNotifRQ<BR>
xmlns:xsi="<A HREF="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A>"<BR>
xsi:schemalocation="<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"<BR>
EchoToken="L00024547MR" TimeStamp="2007-09-10T08:19:06.986850-05:00"<BR>
Version="1.003" ResStatus="Modify"<BR>
xmlns="<A HREF="http://www.opentravel.org/OTA/2003/05">http://www.opentravel.org/OTA/2003/05</A>"><BR>
<BR>
<POS><BR>
<BR>
<Source PseudoCityCode="AUSCTR" ISOCountry="US" /><BR>
<BR>
</POS><BR>
<BR>
<HotelResModifies><BR>
<BR>
<HotelResModify CreateDateTime="2007-09-10T08:19:06.986850-05:00"<BR>
ResStatus="In-house"><BR>
-snip!-<BR>
EOT<BR>
<BR>
my $out_message = <<EOT;<BR>
<OTA_HotelResModifyNotifRS EchoToken="L00024547MR" ResResponseType="Ignored"<BR>
TimeStamp="2007-09-10T08:27:58.53-05:00"><BR>
<Errors><BR>
<Error Language="en-us" Type="3" ShortText="Invalid arrival time"<BR>
Code="294"><BR>
</Error><BR>
</Errors><BR>
</OTA_HotelResModifyNotifRS><BR>
EOT<BR>
<BR>
my @bad_stuff;<BR>
foreach ($in_message, $out_message) {<BR>
my $twig = new XML::Twig;<BR>
$twig->parse($_);<BR>
my $root = $twig->root;<BR>
push @bad_stuff, map { $_->sprint } $root->get_xpath('//Error');<BR>
push @bad_stuff, map { $_->sprint } $root->get_xpath('//Warning');<BR>
}<BR>
<BR>
print join "\n", @bad_stuff;<BR>
print "\n";<BR>
$in_message =~ s/^\n//mg;<BR>
print "$in_message\n";<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>