I am saving a simple XDocument using

xDoc.Save(result.Filename, SaveOptions.OmitDuplicateNamespaces);

When we open the file and process it on a Windows system (Server2008 or Win7) the xml is correct and processes in the next system correctly.

Howevever, when we move to our production system (unix) the xml fails to read correctly.

When we vi the resulting file on the unix box there are three leading control characters. Remove these and the xml processes correctly.

I cannot see these characters in Notepad++ (which shows the file as ANSI/UTF8).

Has anyone any idea what these characters ARE, how they get there...and how to either remove them or stop them appearing?

有帮助吗?

解决方案

You can omit Unicode BOM, just pass new UTF8Encoding(false) to the save method.

Something like this (please treat it as pseudo code):

using(var writer =  new StreamWriter(result.Filename, false, new UTF8Encoding(false))){
    xDoc.Save(writer , SaveOptions.OmitDuplicateNamespaces);
}

其他提示

This the Unicode BOM (byte-order mark).

If it is showing in Linux, get a Unicode capable editor/viewer.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top