Better namespace support in output documents

This handles setting the default namespace correctly when passed an empty prefix and allows for explicit namespace declarations.

We also avoid creating extra namespace nodes or declarations by first checking the in-scope namespaces.