tighten types, improve error printing, and fix an error in cdata

This is just some minor cleanup (and a bug fix). Sometimes libxml2 is overkill -- can you add this to METADATA.jl, please? it would be much appreciated.