我想用XDocument
来解析xml文档,但是我对XML很陌生,以前只使用过JSON。到目前为止,我可以解析每个报告名称,但我试图解析参数列表。当没有节点区分不同参数时,如何解析参数列表?使用XDocument和LINQ解析XML和元素对
var reports = xml.Descendants("Report").Select(reportElement => new
{
Name = reportElement.Attribute("Name").Value,
Parameters = reportElement.Descendants("ParameterList").Select(parameter => new
{
})
});
XML:
<ReportList>
<Report Name="JobNotClose">
<ParameterList>
<Name>@StationCode</Name><Value>LAX</Value>
<Name>@ShipmentType</Name><Value>SE|SI</Value>
</ParameterList>
</Report>
<Report Name="JobWithoutSales">
<ParameterList>
<Name>@StationCode</Name><Value>PA</Value>
<Name>@JobDateFrom</Name><Value>2013-10-1</Value>
<Name>@JobDateTo</Name><Value>2013-10-31</Value>
</ParameterList>
</Report>
</ReportList>
那xml看起来有点小狗给我。参数条目是不是应该是? – Alex
看到这就是我问的,但没有这将如何被格式化。如果这是一个节点,我只是使用'.Descendants()'我真的不知道如何处理它像这样构造 – ChaoticLoki