C# 如何从这个XML中读取值
我试图从soap响应中读取xml。具体如下C# 如何从这个XML中读取值,c#,asp.net,xml,web-services,soap,C#,Asp.net,Xml,Web Services,Soap,我试图从soap响应中读取xml。具体如下 `<OTA_AirLowFareSearchRS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.9.2" PricedItinCount="1" BrandedOneWayItinCount="0" SimpleOneWayItinCount="0" DepartedItin
`<OTA_AirLowFareSearchRS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.9.2" PricedItinCount="1" BrandedOneWayItinCount="0" SimpleOneWayItinCount="0" DepartedItinCount="0" SoldOutItinCount="0" AvailableItinCount="0">
<Success xmlns="http://www.opentravel.org/OTA/2003/05"/>
<Warnings xmlns="http://www.opentravel.org/OTA/2003/05">...</Warnings>
<PricedItineraries xmlns="http://www.opentravel.org/OTA/2003/05">
<PricedItinerary SequenceNumber="1">
<AirItinerary DirectionInd="OneWay">
<OriginDestinationOptions>
<OriginDestinationOption ElapsedTime="1920">
<FlightSegment DepartureDateTime="2017-03-21T21:45:00" ArrivalDateTime="2017-03-22T09:50:00" StopQuantity="0" FlightNumber="7336" ResBookDesigCode="T" ElapsedTime="425">
<DepartureAirport LocationCode="CDL" TerminalID="1"/>
<ArrivalAirport LocationCode="CDA" TerminalID="1A"/>
<OperatingAirline Code="AA" FlightNumber="810"/>
<Equipment AirEquipType="000"/>
<MarketingAirline Code="PP"/>
<DisclosureAirline Code="AC"/>
<MarriageGrp>O</MarriageGrp>
<DepartureTimeZone GMTOffset="-10"/>
<ArrivalTimeZone GMTOffset="11"/>
<TPA_Extensions>
<eTicket Ind="true"/>
</TPA_Extensions>
</FlightSegment>
</OriginDestinationOption>
</OriginDestinationOptions>
</AirItinerary>
</PricedItinerary>
</PricedItineraries>
</OTA_AirLowFareSearchRS>`
任何建议都将受到鼓励。谢谢。您可以这样编写LINQ查询。您可能需要根据需要调整它,但它可以与XML字符串一起使用
var selected = from x in xdoc.Descendants()
where x.NodeType == XmlNodeType.Element
&& x.Name.LocalName == "FlightSegment"
select x;
这是小提琴手:
var selected = from x in xdoc.Descendants()
where x.NodeType == XmlNodeType.Element
&& x.Name.LocalName == "FlightSegment"
select x;