Refactor some of the code, and switch to DOMDocument for validation

This is possibly worth pushing live once we've reviewed it, as it fixes a couple of user reported bugs. One being xs:anyUri, the other being that the previous streaming API we were using missed out some validation errors.