我需要检查ConnectionInd
元素中是否存在特定属性FlightSegment
。如果存在,我将存储该值,如果不存在,我将继续阅读下一个属性。
以下是它是否存在:
<FlightSegment ArrivalDateTime="06-16T06:10" ConnectionInd="O" DepartureDateTime="2013-06-16T00:15" SmokingAllowed="false" eTicket="true">
<Destination ... />
</FlightSegment>
这是如果它不存在:
<FlightSegment ArrivalDateTime="03-27T17:35" DepartureDateTime="2013-03-27T13:30" SmokingAllowed="false" eTicket="true">
<Destination ... />
</FlightSegment>
我正在使用以下代码检查它,但是当没有时ConnectionInd
,它会抛出一个错误说Object reference not set to an instance of an object.
if (FlightSegment.Item(f).Attributes["ConnectionInd"].Value != "" && FlightSegment.Item(f).Attributes["ConnectionInd"] != null)
{
string conInd = FlightSegment.Item(f).Attributes["ConnectionInd"].Value;
}