Как получить первый статус по его <StatusType>
элементам <Code>
является D. Этот LINQ работает, но re sharp говорит, что x.Element("StatusType")
Возможная ошибка отображения nullreference.Исключение исключения элементов вложенного XML
var aaa = track.Descendants("Status")
.SingleOrDefault(x => x.Element("StatusType") != null &&
x.Element("StatusType").Element("Code").Value == "D");
XML: -
<Activity>
<ActivityLocation>
<Address>
<City>WILSLLE</City>
<StateProvinceCode>oR</StateProvinceCode>
<PostalCode>978880</PostalCode>
<CountryCode>US</CountryCode>
</Address>
<Code>M7</Code>
<Description>RECEIVER</Description>
<SignedForByName>abc</SignedForByName>
</ActivityLocation>
<Status>
<StatusType>
<Code>D</Code>
<Description>DELIVERED</Description>
</StatusType>
<StatusCode>
<Code>KB</Code>
</StatusCode>
</Status>
<Date>20150504</Date>
<Time>085100</Time>
</Activity>
<Activity>
<ActivityLocation>
<Address>
<City>TUALATIN</City>
<StateProvinceCode>OR</StateProvinceCode>
<CountryCode>US</CountryCode>
</Address>
</ActivityLocation>
<Status>
<StatusType>
<Description>OUT FOR DELIVERY</Description>
</StatusType>
<StatusCode>
<Code>DS</Code>
</StatusCode>
</Status>
<Date>20150504</Date>
<Time>045600</Time>
</Activity>