質問

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