4

I'm using NuSOAP to interact with a third party API, including running database queries and retrieving the results. It's been working quite reliably, but I just ran into an issue with one specific query. Instead of returning results, NuSOAP generated an error: XML error parsing SOAP payload on line 2: Invalid character

Turns out that the result set contained the following: Léa Lincoln. When I manually changed the accented character to a "regular" one, the query worked fine with no errors from NuSOAP.

So, my question is how to handle this going forward. I can't control the data coming from the database, and I need for NuSOAP not to throw an error and stop every time there's a non-standard character. Thanks. --Jeff

jalperin
  • 2,664
  • 9
  • 30
  • 32
  • Try to encode the xml with UTF-16 `` – HamZa Jun 22 '12 at 18:02
  • I can't change what's coming from the server. Is this something I can do from the client side (i.e. in NuSOAP?) – jalperin Jun 22 '12 at 18:09
  • I have no idea, try to checkout the docs, btw i found this link wich may help http://sourceforge.net/projects/nusoap/forums/forum/193579/topic/3718945 ... Regards – HamZa Jun 22 '12 at 18:20
  • I tried setting $soap_defencoding to 'UTF-8' and 'UTF-16' in NuSOAP, but it didn't make any difference. The link you pointed me to WAS helpful though. I added the suggested hack which seemed to resolve the problem for me. function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){ parent::nusoap_base(); // Hack by CAZypedia crew to fix character encoding of NCBI XML data from SOAP // This prevents non-English characters from causing the parser to choke. $xml = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $xml); // End hack. – jalperin Jun 22 '12 at 19:29
  • If you want to write your comment as an answer, I'll mark it answered. Thanks! – jalperin Jun 22 '12 at 19:30

2 Answers2

5

After searching and testing seems that a hack by CAZypedia crew was the solution:

function nusoap_parser($xml,$encoding='UTF-8',$method='',$decode_utf8=true){
    parent::nusoap_base();

    // Hack by CAZypedia crew to fix character encoding of NCBI XML data from SOAP
    // This prevents non-English characters from causing the parser to choke.
    $xml = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $xml);
    // End hack.
    $this->xml = $xml;
    $this->xml_encoding = $encoding;
    $this->method = $method;
    $this->decode_utf8 = $decode_utf8;

Link: http://sourceforge.net/projects/nusoap/forums/forum/193579/topic/3718945

HamZa
  • 14,671
  • 11
  • 54
  • 75
1

I had this same problem, and I solved it by change the line var $soap_defencoding = 'UTF-8' at the files nusoap.php and class.nusoap_base.php

In those files there are two lines, $soap_defencoding = 'UTF-8' and $soap_defencoding = 'ISO-8859-1', one is commented and the other is not.

I tried moving the comments from one option to the other, and it worked!

Thiago Brauer
  • 321
  • 4
  • 9