XPath syntax provides a simple way to search for the presence of an
Error
node, as well as an easy way to retrieve the error code and message. The following code
snippet uses Perl and the XML::XPath module to determine if an error occurred during a
request. If an error occurred, the code prints the first error code and message in the
response.
use XML::XPath;
my $xp = XML::XPath->new(xml =>$response);
if ( $xp->find("//Error") )
{print "There was an error processing your request:\n", " Error code: ",
$xp->findvalue("//Error[1]/Code"), "\n", " ",
$xp->findvalue("//Error[1]/Message"), "\n\n"; }