Welcome to Geekdojo Sign in | Join | Help

XmlWriterSettings.Encoding vs. XmlWriter.WriteProcessingInstruction

I was using XmlWriter [using .NET v2 beta2] to write xml to a stream. The thing I had to write was like :-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<entry xmlns="
http://purl.org/atom/ns#">
...
</entry>

to write out the first line i.e. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
I went looking around settings in XmlWriterSettings and I did

[IrontPython]

writerSettings = XmlWriterSettings()
writerSettings.Indent = True
writerSettings.Encoding = Encoding.UTF8

writer = XmlWriter.Create(Console.Out, writerSettings)

...

Then, I see the Xml output and it shows

<?xml version="1.0" encoding="IBM437"?>

I see IBM437 istead of UTF-8 ??

Later, I manage to get the desired result by

writerSettings = XmlWriterSettings()
writerSettings.Indent = True
writer = XmlWriter.Create(Console.Out, writerSettings)

writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"")
...

is the behaviour of XmlWriter correct ? isn't the default encoding of Xml documents UTF-8 ?

Published Saturday, July 16, 2005 3:31 PM by richardhsu
Filed Under:

Comments

Anonymous comments are disabled