I need to parse a SOAP response in perl:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:iden="http://identifycaller.customermanagement.schema.amx.com"/>
<soapenv:Body xmlns:iden="http://identifycaller.customermanagement.schema.amx.com">
<ns2:Fault xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
<faultcode>ns2:server</faultcode>
<faultstring>Error interno del servicio. Por favor contacte al administrador. </faultstring>
<detail>
<ns2:InternalSystemErrorException xmlns:ns2="http://commonsexceptions.schema.amx.com">
<ns2:errorCode>1049581</ns2:errorCode>
<ns2:errorMsg>Error tecnico</ns2:errorMsg>
<ns2:message>Error interno del servicio. Por favor contacte al administrador.</ns2:message>
</ns2:InternalSystemErrorException>
</detail>
</ns2:Fault>
</soapenv:Body>
</soapenv:Envelope>
My code:
my $xml = $response->content;
my $dom = XML::LibXML->load_xml( string => (\$xml) );
my $xpc = XML::LibXML::XPathContext->new($dom);
$xpc->registerNs('ns2', 'http://commonsexceptions.schema.amx.com');
my $errorCode = $xpc->findvalue('/*/ns2:errorCode');
my $errorMessage = $xpc->findvalue('/*/ns2:message');
print "Codigo $errorCode: $errorMessage\n";
I am unable to get the correct XPATH expression to get ns2:errorCode and ns2:message. I've read lots of answers and will continue playing with this but time is getting short.
I'm using perl 5.16 under windows but plan to deploy on perl 5.8.4 under solaris. I'm also using XML::LibXML.