I have noticed that XmlWriter.WriteRaw appears to not work properly (it escapes xml characters) when the writer is created using XElement.CreateWriter. The below test case reproduces the problem. Is my usage incorrect? Does anyone know how to achieve the desired behavior? I need to be able to write a raw xml string to an XmlWriter and incorporate that xml into an XElement.
[Test]
public void XElementWriterTest()
{
var xelement = new XElement("test");
using (var writer = xelement.CreateWriter())
{
writer.WriteRaw(@"<some raw='xml' />");
}
Assert.That(xelement.ToString(), Is.EqualTo(@"<test><some raw='xml' /></test>"));
// actual : "<test><some raw='xml' /></test>"
}