Hi all.
I can't understand the problem with my code...
I wrote a simple test function to write an XML document and in the
resulting file I find 3 strange chars before the document starting.
=== CODE ===
using( XmlTextWriter w = new
XmlTextWriter("test2.xml",System.Text.Encoding.UTF8) )
{
w.Namespaces = false;
w.Indentation = 4;
w.Formatting = Formatting.Indented;
w.WriteStartDocument();
w.WriteStartElement("root");
w.WriteStartElement("item");
w.WriteAttributeString("attr","123");
w.WriteEndElement();
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
}
===
And the result I get is:
===
<?xml version="1.0" encoding="utf-8"?>
<root>
<item attr="123" />
</root>
===
Help me please!
> And the result I get is:
>
[quoted text clipped - 8 lines]
>
> Help me please!
Sorry, these chars aren't ASCII standards so they are not visible
here...
Value in HEX:
EF BB BF
These are Unicode Byte Order Mark and they are ok.
But if you really really want to omit them (BOM is optional in UTF-8),
use this:
XmlTextWriter("test2.xml", new System.Text.UTF8Encoding(false)) )

Signature
Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net
> Hi all.
> I can't understand the problem with my code...
[quoted text clipped - 33 lines]
>
> Help me please!
Mat - 24 Oct 2006 13:24 GMT
> These are Unicode Byte Order Mark and they are ok.
> But if you really really want to omit them (BOM is optional in UTF-8),
> use this:
> XmlTextWriter("test2.xml", new System.Text.UTF8Encoding(false)) )
Perfect !
Thank you very much Oleg.
Just for reference:
http://en.wikipedia.org/wiki/Byte_Order_Mark
I learnt a new thing :)