In general I try to avoid using the libxml2 API outside of xml.c, but in this case we can make an exception