Reputation: 63
Currently I have the following code:
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var myObject = new MyObject() {Text = "€ 232.22"};
StringBuilder sb = new StringBuilder();
var xmlWriterSettings = new XmlWriterSettings();
XmlWriter writer = XmlWriter.Create(sb, xmlWriterSettings);
new XmlSerializer(typeof(MyObject)).Serialize(writer, myObject);
Console.WriteLine(sb.ToString());
Console.ReadKey();
}
}
[Serializable]
public class MyObject
{
public MyObject()
{
}
[XmlAttribute()]
public string Text { get; set; }
}
}
And the issue I have id that currently the serializer when i give it a euro symbol € it returns a ?, so then I tried passing € but it encodes the & and returns € Anyone know of an elegant way to solve this issue?
Many thanks,
Chris
Upvotes: 0
Views: 1940
Reputation: 574
Ensure that you are using proper encoding style one the xml document it-self, as well as in your serializing and deserializing steps.
You ensure this by using utf-8 encoding throughout the specification and handling of the xml document.
Upvotes: 1
Reputation: 113222
It's not the serialiser, it's the Console. Try Console.WriteLine("€");
or try Console.ReadKey(false);
and then type € and you get the same results.
(Assuming that is, that your console fonts don't have a €, which the default don't).
The € character isn't a "special character" in anyway, but a font can't handle ABC if it doesn't have glyphs for them.
Upvotes: 0