Try the following:
using System.Text;
using System.Xml;
XmlDocument dom = GetDocument()
byte[] bytes = Encoding.Default.GetBytes(dom.OuterXml);
If you want to preserve the text encoding of the document, then change the Default
encoding to the desired encoding, or follow Jon Skeet's suggestion.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…