I have a xml file which has umlauts in it like so:
<NameGe>ËÇ</NameGe>
Is there a way to read this file and write it out like so:
<NameGe>Öç</NameGe>
so basically it should write the numeric/encoded value of the umlaut.
Regards.
I have a xml file which has umlauts in it like so:
<NameGe>ËÇ</NameGe>
Is there a way to read this file and write it out like so:
<NameGe>Öç</NameGe>
so basically it should write the numeric/encoded value of the umlaut.
Regards.
You can do it by overriding WriteString
of XmlTextWriter
MemoryStream m = new MemoryStream();
MyWriter xmlWriter = new MyWriter(m);
XDocument xDoc = XDocument.Parse(xml);
xDoc.Save(xmlWriter);
xmlWriter.Flush();
string s = Encoding.UTF8.GetString(m.ToArray());
-
public class MyWriter : XmlTextWriter
{
public MyWriter(Stream s) : base(s,Encoding.UTF8)
{
}
public override void WriteString(string text)
{
base.WriteRaw(HttpUtility.HtmlEncode(text));
}
}
Use HttpUtility.HtmlEncode
and HttpUtility.HtmlDecode
.