| « PreviousNext » | |
![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
Typically, you want your application to check whether or not a request
generated an error before spending any time processing results. The easiest way to find
out if an error occurred is to look for an
Error
node in the response.
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"; }