Obtenir un XML Encodé UTF-8 ?
Bonjour,
Je me suis fait une petite XML Factory
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
public class XMLFactory
{
public XDocument CurrentDocument { get; set; }
public XMLFactory(string xmlDocumentString)
{
this.CurrentDocument = XDocument.Load(new StringReader(xmlDocumentString));
}
public string SaveToString()
{
string toReturn = string.Empty;
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Encoding = new UTF8Encoding();
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb,xmlWriterSettings))
{
this.CurrentDocument.Save(writer);
}
toReturn = sb.ToString();
return toReturn;
}
} |
Lorsque je passe la chaine XML au constructeur, elle arrive en utf-8.
Lorsque j'utilise le this.CurrentDocument.Save(writer); elle ressort en utf-16 malgré le
Code:
1 2
| XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Encoding = new UTF8Encoding(); |
Vous pourriez m'aider à faire en sorte que l'encodage ne change pas ?
D'avance merci
Laurent