Looks good, though I do have a minor nit. I would suggest changing this line instead:
xmldecl = re.compile(b'<[?]xml\\s')
to:
xmldecl = re.compile('<[?]xml\\s')
Reasoning: there is no need to encode the XML string into bytes if you can just compare it to a string using the regex. (In other words, the .encode() is doing a small amount of unnecessary extra work.)
Looks good, though I do have a minor nit. I would suggest changing this line instead:
xmldecl = re.compile( b'<[?]xml\ \s')
to:
xmldecl = re.compile( '<[?]xml\ \s')
Reasoning: there is no need to encode the XML string into bytes if you can just compare it to a string using the regex. (In other words, the .encode() is doing a small amount of unnecessary extra work.)