0

以下にリストされているxmlがあります。C# で list<> にデシリアライズしたいと思います。リスト エンティティ名の ASIwizard と Wizard の二重化に対処する方法はありますか? それが ASIwizard または Wizard だけであれば実行できますが、各要素に 2 つのエンティティ名がある場合はどうすればよいかわかりません。

<ASiwizards>
  <ASiwizard>
    <Wizard>
      <id>1</id>
      <title>Headlight Wizard</title>
      <description>This wizard will help troubleshoot issues related to the headlight functionality of the eBike controller</description>
      <created>2012-04-27 14:35:34</created>
      <modified>2012-04-27 14:35:34</modified>
    </Wizard>
  </ASiwizard>
  <ASiwizard>
    <Wizard>
      <id>2</id>
      <title>Wiring Harness</title>
      <description/>
      <created>2012-04-27 19:11:33</created>
      <modified>2012-04-27 19:11:33</modified>
      </Wizard>
  </ASiwizard>
</ASiwizards>
4

1 に答える 1

0

これでうまくいくはずです:

var xElement = XElement.Parse(xml);
var items = xElement
  .Elements("ASiwizard")
  .Select(x => x.Element("Wizard"))
  .Select(
    x => new {
      Id = (Int32) x.Element("id"),
      Title = (String) x.Element("title"),
      Description = (String) x.Element("description"),
      Created = (DateTime) x.Element("created"),
      Modified = (DateTime) x.Element("modified")
    }
  )
  .ToList();
于 2012-04-30T19:39:42.357 に答える