【发布时间】:2015-11-06 13:23:13
【问题描述】:
我无法实现这种序列化。我有这些课程
public class Data
{
[XmlElement("Name")]
public string Name { get; set; }
}
[XmlRoot("Data")]
public class DataA : Data
{
[XmlElement("ADesc")]
public string ADesc { get; set; }
}
[XmlRoot("Data")]
public class DataB : Data
{
[XmlElement("BDesc")]
public string BDesc { get; set; }
}
当我序列化 DataA 或 DataB 时,我应该得到以下结构中的 XML:
<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="" i:type="DataA">
<Name>A1</Name>
<ADesc>Description for A</ADesc>
</Data>
<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="" i:type="DataB">
<Name>B1</Name>
<BDesc>Description for b</BDesc>
</Data>
我得到的是下面的(没有 i:type="..." 和 xmlns="")
<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Name>A1</Name>
<ADesc>Description for A</ADesc>
</Data>
<Data xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Name>B1</Name>
<BDesc>Description for b</BDesc>
</Data>
我不确定我在这里缺少什么。任何建议都会有所帮助。
- 吉里哈
【问题讨论】:
标签: c# xml-serialization