我正在使用 XmlSerializer 反序列化配置文件。我希望能够将 Xml 元素的子内容提取到字符串字段中。此子内容可以是 xml 本身。
一个简单的例子:
public class Configuration
{
[XmlAttribute]
public string MyAttribute { get; set; }
[XmlText]
public string Content { get; set; }
}
我正在尝试解析以下内容:
<Configuration MyAttribute="foo">
<SomeOtherXml />
</Configuration>
我希望将 Content 属性设置为,"<SomeOtherXml />"
但我似乎无法让它工作。我不想将内容封装在 CDATA 或类似文件中。
这是可能的还是我需要手动处理我的配置文件的解析?
谢谢