See how "a" element is not closed? Note also how the "</a>" is missing, as well as document end. I wonder why it broke off so much.
Because you told QXmlStreamWriter to write an empty "<a/>" element. By calling output.write() directly, you did something that the stream writer has no knowledge about. It doesn't know what you did "behind its back". As far as it knows, all you did was to tell it to start an "a" element, then immediately end it.

Try wysota's idea.

But why can't you simply write out the raw XML using QXmlStreamWriter? Are the "<b>" element names unknown at compile time? Or is it only the text inside the "b" element?