Use xml-parse-region to parse stream header

This lets us get rid of some ugly hacks, and will make it easier to
extract other attributes from the header.