Can someone please be explain why System.Xml.XmlTextWriter escapes the ampersand in front of what I thought was a valid unicode character reference:
[TestMethod]
public void TestEncoding()
{
using (StringWriter sw = new StringWriter())
{
XmlWriter writer = new XmlTextWriter(sw);
const string testChar = "–";
writer.WriteString(testChar);
Assert.AreEqual(testChar, sw.ToString());
writer.Close();
}
}
fails with the message
Assert.AreEqual failed. Expected:<–>. Actual:<&#8211;>.
Is there a way to escape this behavior, while correctly maintaining conversion of isolated or invalid ampersands to & ?
No comments:
Post a Comment