.Net Xml 反序列化
我有以下 XElement
<Issue Type="Duplicate" Distance="1">
<Record>
<ID>6832</ID>
<Name_First>JAMES </Name_First>
<Name_Last>SMITH</Name_Last>
<Company>SMITH CO.</Company>
</Record>
<Record>
<ID>6831</ID>
<Name_First>JAMES</Name_First>
<Name_Last>SMITH</Name_Last>
<Company>SMITH CO.</Company>
</Record>
</Issue>
我试图将其反序列化到此对象中
public class Issue
{
[XmlAttribute]
public string Type { get; set; }
[XmlArrayItem(typeof(XElement), ElementName = "Record")]
public List<XElement> Record { get; set; }
}
该类型工作没有问题,但我无法将两个 Record 节点放入该对象的 Record 列表中。
是否可以在不重写 ISerialized 和编写自定义代码的情况下实现?
I have the following XElement
<Issue Type="Duplicate" Distance="1">
<Record>
<ID>6832</ID>
<Name_First>JAMES </Name_First>
<Name_Last>SMITH</Name_Last>
<Company>SMITH CO.</Company>
</Record>
<Record>
<ID>6831</ID>
<Name_First>JAMES</Name_First>
<Name_Last>SMITH</Name_Last>
<Company>SMITH CO.</Company>
</Record>
</Issue>
I'm trying to Deserialize it into this object
public class Issue
{
[XmlAttribute]
public string Type { get; set; }
[XmlArrayItem(typeof(XElement), ElementName = "Record")]
public List<XElement> Record { get; set; }
}
The type works no problem, but I can't get the two Record nodes into the Record list of the object.
Is it possible without overriding ISerializable and writing custom code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
我认为这告诉序列化器多个 Record 元素将进入列表。
Try this:
I think that tells the serializer that multiple Record elements will go in the list.
实现具有 ID、Name_First、Name_Last 和 Company 字段的 Record 类
Implement Record class which has ID, Name_First, Name_Last and Company fields