【发布时间】:2020-04-30 06:14:27
【问题描述】:
我要做的是从下面 xml 的 Included_By_Organization 集合中的 ID 标记上的 type 属性中获取属性值。我可以很好地获取值,但属性返回 null。
包含在组织对象示例中:
Type: null
XML
<wd:Included_by_Organizations wd:Descriptor="RU7860 Europe Forwarding Overhead">
<wd:ID wd:type="WID">b8129574800601751d8538accb023f35</wd:ID>
<wd:ID wd:type="Organization_Reference_ID">RU7860</wd:ID>
<wd:ID wd:type="Custom_Organization_Reference_ID">RU7860</wd:ID>
</wd:Included_by_Organizations>
xml 数组的类
[XmlAttribute("type")]
public string Type { get; set; }
[XmlText]
public string Value { get; set; }
public IncludedByOrganization()
{
}
获取 xml 值的类
[XmlElement("Reference_ID")]
public string CostCenterId { get; set; }
[XmlElement("code")]
public string Code { get; set; }
[XmlElement("name")]
public string Name { get; set; }
[XmlArray("Included_by_Organizations")]
[XmlArrayItem("ID")]
public IncludedByOrganization[] IncludedByOrganization { get; set; }
去沙化方法
ReportData reportDataList = new ReportData();
XmlSerializer serializer = new XmlSerializer(typeof(ReportData));
using (var reader = XmlReader.Create(filePath))
{
ReportData reportData = (ReportData)serializer.Deserialize(reader);
reportDataList = reportData;
}
return reportDataList;
【问题讨论】: