【发布时间】:2015-06-16 01:47:15
【问题描述】:
我正在寻找一种方法来创建一个 xml 元素,该元素将接受可能包含如下所示的 html 元素(或任何其他有效的 xml 元素)的文本字符串:
"Test text with <strong>custom nodes</strong> that shouldn't be encoded"
我尝试将XmlAnyElement 与XmlNode[] 结合使用,但没有成功。
我想要的输出应该是这样的:
<Root>
<Text>
Test text with <strong>custom nodes</strong> that shouldn't be encoded
</Text>
</Root>
对于这个类:
public class Root
{
// Problematic property
public string Text { get; set; }
}
实现这种行为的最简单方法是什么(部分问题是我的元素可能以纯文本开头和/或结尾)?
【问题讨论】:
标签: c# html xml xml-serialization xmlserializer