2

いくつかのxmlを読み取り、クラス構造にデータを入力する必要があります。誰かが私にそのためのきちんとしたコードを提供してくれたらとても嬉しいです。

私の簡略化されたクラス構造:

public class Event
{
    [XmlAttribute("Id")]
    public string Id { get; set; }

    [XmlElement("StartTimes")]
    public Collection<StartTime> StartTimeCollection;        
}

public class StartTime
{
    [XmlAttribute("Time")]
    public string Start { get; set; }
    [XmlAttribute("Mon")]
    public bool Monday { get; set; }
    [XmlAttribute("Tue")]
    public bool Tuesday { get; set; }
    [XmlAttribute("Wed")]
    public bool Wednesday { get; set; }
    [XmlAttribute("Thu")]
    public bool Thursday { get; set; }
    [XmlAttribute("Fri")]
    public bool Friday { get; set; }
    [XmlAttribute("Sat")]
    public bool Saturday { get; set; }
    [XmlAttribute("Sun")]
    public bool Sunday { get; set; }
}

xmlは次のようになります:

<Event Id="f7cfc3a5-5b1b-4941-8d7b-f8a4a71fa530">
  <StartTimes>
    <StartTime Time="19:00" Mon="false" Tue="false" Wed="false" Thu="false" Fri="true" Sat="false" Son="false"/>
  </StartTimes>
</Event>

そして、それは私のlinqステートメントがどのように見えるかです:

from x in doc.Descendants("Event")
select new Event()
{
Id = x.Attribute("Id").Value,
StartTimeCollection = x.Descendants("StartTimes") ????????? <-- That's the tricky part for me
}

よろしく

4

1 に答える 1