public class Records
{
[XmlElement("Record")]
public List<Record> Items { get; } = new();
}
public class Record
{
[XmlAttribute("contentId")]
public int ContentId { get; set; }
[XmlElement("Record")]
public Record ChildRecord { get; set; }
[XmlElement("Field")]
public List<Field> Fields { get; } = new();
}
public class Field
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlElement("Reference")]
public List<Reference> References { get; } = new();
[XmlArray("ListValues")]
public List<ListValue> ListValues { get; } = new();
[XmlText]
public string Content { get; set; }
}
public class Reference
{
[XmlAttribute("id")]
public int Id { get; set; }
}
public class ListValue
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlText]
public string Content { get; set; }
}
From the comments, your question is how you deserialize the nested records.
A class structure like this seems to work:
public class Records
{
[XmlElement("Record")]
public List<Record> Items { get; } = new();
}
public class Record
{
[XmlAttribute("contentId")]
public int ContentId { get; set; }
[XmlElement("Record")]
public Record ChildRecord { get; set; }
[XmlElement("Field")]
public List<Field> Fields { get; } = new();
}
public class Field
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlElement("Reference")]
public List<Reference> References { get; } = new();
[XmlArray("ListValues")]
public List<ListValue> ListValues { get; } = new();
[XmlText]
public string Content { get; set; }
}
public class Reference
{
[XmlAttribute("id")]
public int Id { get; set; }
}
public class ListValue
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlText]
public string Content { get; set; }
}
See this doc on how to use the various attributes.
I haven't bothered to deserialize all of the attributes, or the Metadata or LevelCounts sections -- those are an exercise for the reader!
Use an XmlSerializer, for example:
using var reader = new StringReader(input);
var records = (Records)new XmlSerializer(typeof(Records)).Deserialize(reader);
发布评论
评论(2)
从评论来看,您的问题是如何反序列化嵌套记录。
像这样的类结构似乎有效:
请参阅 本文档介绍如何使用各种属性。
我没有费心去反序列化所有属性,或者
Metadata
或LevelCounts
部分 - 这些都是读者的练习!使用
XmlSerializer
,例如:在 dotnetfiddle.net 上查看。
From the comments, your question is how you deserialize the nested records.
A class structure like this seems to work:
See this doc on how to use the various attributes.
I haven't bothered to deserialize all of the attributes, or the
Metadata
orLevelCounts
sections -- those are an exercise for the reader!Use an
XmlSerializer
, for example:See it on dotnetfiddle.net.
将数据平铺到一张表中虽然很混乱,但可以做到。见下文
To flatten data into one table is messy but can be done. See below