0

I have a database which contains a list of users, and I occasionally pass that user list via a webservice to a remote machine. I had a call from one of our remote facilities to say that none of the new users were showing up.

A little research turned up the problem - the webservice serves up the user list from the database as an XML file, and one of the users has a non-standard character in her name ("María"). The target PC sees this non-standard character and chokes because the XML is "broken", and therefore NONE of the records after that point are processed.

The short-term fix was easy - María became Maria. Suddenly all the records would process without a problem. However the long-term solution is what concerns me. How can I somehow force recognition of these non-standard characters?

Please note that the webservice simply takes the contents of the database table and spits them out as XML; the XML file isn't anything I'm forming manually, but is rather just how the webservice does business.

Thanks in advance for your help!

Don Quixote
  • 235
  • 1
  • 5
  • 15
  • If you have no control over how the web service formats (encodes) the XML then you have no choice but to send it sanitized data. This is a post on how to remove diacritics http://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net – paparazzo Nov 26 '13 at 19:36

1 Answers1

0

I guess you are creating XML by string concatenation. You should be using an XmlWriter to create your XML output. It will take care of correct encoding of non-ascii characters, xml entities and many other things.

If that's not the case, then xml is built correctly and xml parsing code has problems.

Erdogan Kurtur
  • 3,630
  • 21
  • 39
  • The XML is generated dynamically by the webservice... I declare a dataset and point it to the table, and the webservice returns that dataset (automatically converting it to XML in the process). The consumer declares a dataset and points it to the webservice, automatically converting the XML back into a dataset. I don't actually deal with the XML directly; rather, .NET creates the XML and consumes it in the back-end. – Don Quixote Nov 26 '13 at 16:06
  • exactly what exception do you receive? – Erdogan Kurtur Nov 26 '13 at 16:15
  • An invalid character was found in text content.'. Could not find prepared statement with handle 0. Could not find prepared statement with handle 0. sp_xml_removedocument: The value supplied for parameter number 1 is invalid. The XML parse error 0xc00ce508 occurred on line number 111285, near the XML text " Mar". The statement has been terminated. – Don Quixote Nov 26 '13 at 16:21