eczarny/xmlrpc — Issue #12: Better handling of invalid XML responses
Author: koke
Created: 2011-12-15 13:54:37+00:00
State: open

Some misconfigured hosts or software can return invalid XML, which NSXMLParser can't parse.

There are a few things that can be done to be smart and "extract" the valid XML inside a response:

* Discard any invalid UTF-8 characters
* Discard any data before ` any Unicode character, excluding the surrogate blocks, FFFE, and FFFF

* For extra validation, add the [Tidy library](http://tidy.sourceforge.net/) and the Objective-C tidy wrapper [CTidy](https://github.com/TouchCode/TouchXML/tree/master/Source/Tidy), and correct any markup mistakes.

Note that the tidy library is around ~28K lines of code and adds ~1MB to your binary (in iOS at least).

I've put the current implementation in [WordPress for iOS](http://ios.wordpress.org) in a separate file: https://gist.github.com/1481105

It should probably be used in `[XMLRPCResponse initWithData:]`:

* Filtering the data before passing it to the parser: faster if you deal with hosts you don't control
* or doing a first attempt to parse and running through the cleaning filters if there's a parsing error: faster if you control the host and 99% of the times the response will be proper XML