XML error (invalid character) while retrieving results using NuSOAP

I use NuSOAP to interact with a third-party API, including starting database queries and getting results. It works quite reliably, but I just ran into a problem with one specific request. Instead of returning results, NuSOAP generated an error: XML error parsing SOAP payload on line 2: Invalid character

It turns out that the result set contains the following: LΓ©a Lincoln . When I manually changed the accented character to "normal", the request worked fine, without errors from NuSOAP.

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

+4
source share
2 answers

After searching and testing, it seems that hacking the CAZypedia team was a 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

+5
source

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

There are two lines in these files: $ soap_defencoding = 'UTF-8' and $ soap_defencoding = 'ISO-8859-1', one of them is commented out and the other is not.

I tried moving the comments from one option to another and it will work!

+1
source

All Articles