public static void Main()
var xmlExportFile = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XProcessingInstruction("qbxml", "version=\"2.0\""),
new XElement("QBXMLMsgsRq",
new XAttribute("onError", "stopOnError")
var xmlString = string.Empty;
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream, System.Text.Encoding.UTF8))
xmlExportFile.Save(writer);
xmlString = System.Text.Encoding.UTF8.GetString(stream.ToArray());
Console.WriteLine(xmlString);