Workaround for bug in lxml https://bugs.launchpad.net/lxml/+bug/1281139

This bug likely impacts lots of other code locations, but hopefully it
will be fixed in lxml soonish. For the moment, I will add workarounds as
and when I discover they are needed.