Getting "" at the beginning of my XML File after save()

Posted by Remy on Stack Overflow See other posts from Stack Overflow or by Remy
Published on 2011-01-06T11:25:52Z Indexed on 2011/01/06 12:53 UTC
Read the original article Hit count: 309

Filed under:
|
|
|
|

I'm opening an existing XML file with c# and I replace some nodes in there. All works fine. Just after I save it, I get the following characters at the beginning of the file:

  (EF BB BF in HEX)

The whole first line:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>

The rest of the file looks like a normal XML file.
The simplified code is here:

XmlDocument doc = new XmlDocument();
doc.Load(xmlSourceFile);
XmlNode translation = doc.SelectSingleNode("//trans-unit[@id='127']");
translation.InnerText = "testing";
doc.Save(xmlTranslatedFile);

I'm using a C# WinForm Application. With .NET 4.0.

Any ideas? Why would it do that? Can we disable that somehow? It's for Adobe InCopy and it does not open it like this.

UPDATE: Alternative Solution:

Saving it with the XmlTextWriter works too:

XmlTextWriter writer = new XmlTextWriter(inCopyFilename, null);
doc.Save(writer);

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET