views:

26

answers:

1

Hi when I do this:

using (XmlWriter xw = new XmlTextWriter(fcService.SetCIRIFilePath(), Encoding.UTF8))
        {
            debts.Save(xw);
            xw.Flush();
        }

My debts object is a XDocument object which I populated using LINQ to XML. However when I save it, it looks fine in notepad, but when opened with a binary/hex editor it shows these 3 characters at the start of the XML:

<?xml version

This is stopping it being parsed by a 3rd party. Any ideas how I can stop it doing that?

+2  A: 

Try telling the UTF-8 encoder not to produce the Byte-order-mark, like this:

// http://msdn.microsoft.com/en-us/library/s064f8w2.aspx
using (XmlWriter xw = new XmlTextWriter(fcService.SetCIRIFilePath(), new System.Text.UTF8Encoding(false)))
        {
            debts.Save(xw);
            xw.Flush();
        }
David L.-Pratte
Thank you so much!
David