.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Problems writing XML
 

Problems writing XML

Hi,

I'm creating an XmlDocument and trying to save it to a file. I find if I save via an XmlTextWriter or StreamWriter, I get 3 extra bytes at the beginning of the file. They are non-printable ascii, so they don't show up in a viewer, but the 3rd party import app doesn't like it.

IE,
XmlTextWriter writer = new XmlTextWriter(filename, System.Text.Encoding.UTF8);
xmlDoc.Save(writer);

If I call save with the filename directly, there are no extra bytes, but an element gets an extra xmlns="" attribute, which violates the schema.

IE, xmlDoc.Save(filename);
outputs ...
<SomeElement xmlns="">

Anyone seen this before? Any ideas on how to work around these? Thanks


Pointman2005
That's the BOM. To suppress it, use the XmlTextWriter(Stream, Encoding) constructor, passing a StreamWriter for the Stream argumentthat you created with StreamWriter(String).
Hans Passant.
nobugz
That's the BOM. To suppress it, use the XmlTextWriter(Stream, Encoding) constructor, passing a StreamWriter for the Stream argumentthat you created with StreamWriter(String).
Hans Passant.
nobugz

You can use google to search for other answers

Custom Search

More Threads

• InstallUtil failure
• Process and StartInfo
• Developing .Net Framework v2.0 Apps
• Is .NET Framework and .NET Platfoam two or or same?
• How to split a large csv files to smaller
• FileSystemWatcher....
• how to solve The Undo operation encountered
• Least common denominator
• Windows XP Home Edition
• Language Problem ..... ?