【发布时间】:2017-07-07 15:48:06
【问题描述】:
从下面的 XML 中,我需要找到 FlightSegmentReference ref 等于 BA2759 的所有航班的信息,然后将一些细节从父元素传递给一个类
If Len(inFlightNo) > 0 Then
Dim xdoc As XDocument = XDocument.Parse(rawXML)
Dim results As IEnumerable(Of Offer) =
From offer In xdoc.Descendants(myns + "FlightSegmentReference")
Where offer.Attribute("ref") = inFlightNo
Select New Offer With
{.FlightRef = offer.Attribute("ref")}
'Return results
End If
此示例运行良好...但是我需要获取更多数据以传递给我的班级,例如 TotalAmount SimpleCurrancyPrice 和 OfferItemID
If Len(inFlightNo) > 0 Then
Dim xdoc As XDocument = XDocument.Parse(rawXML)
Dim results As IEnumerable(Of Offer) =
From offer In xdoc.Descendants(myns + "FlightSegmentReference")
Where offer.Attribute("ref") = inFlightNo
Select New Offer With
{.FlightRef = offer.Attribute("ref"),
.Price = ????,
.OfferItemID = ????
}
'Return results
End If
在我的课堂上获取 SimpleCurrencyPrice 和填充 Price 的最佳实践方法是什么
这里是 XML
<AirlineOffers>
<TotalOfferQuantity>1156</TotalOfferQuantity>
<Owner>BA</Owner>
<AirlineOffer RequestedDateInd="true">
<OfferID Owner="BA">OFFER1</OfferID>
<TotalPrice>
<SimpleCurrencyPrice Code="GBP">129.50</SimpleCurrencyPrice>
</TotalPrice>
<PricedOffer>
<OfferPrice OfferItemID="1">
<RequestedDate>
<PriceDetail>
<TotalAmount>
<SimpleCurrencyPrice Code="GBP">129.50</SimpleCurrencyPrice>
</TotalAmount>
<BaseAmount Code="GBP">84.00</BaseAmount>
<Taxes>
<Total Code="GBP">45.50</Total>
</Taxes>
</PriceDetail>
<Associations>
<AssociatedTraveler>
<TravelerReferences>SH1</TravelerReferences>
</AssociatedTraveler>
</Associations>
</RequestedDate>
</OfferPrice>
<Associations>
<ApplicableFlight>
<FlightSegmentReference ref="BA2759">
<ClassOfService>
<Code>O</Code>
<MarketingName>Euro Traveller</MarketingName>
</ClassOfService>
</FlightSegmentReference>
</ApplicableFlight>
<PriceClass>
<PriceClassReference>Plus</PriceClassReference>
</PriceClass>
</Associations>
<Associations>
<ApplicableFlight>
<FlightSegmentReference ref="BA2764">
<ClassOfService>
<Code>Q</Code>
<MarketingName>Euro Traveller</MarketingName>
</ClassOfService>
</FlightSegmentReference>
</ApplicableFlight>
<PriceClass>
<PriceClassReference>Plus</PriceClassReference>
</PriceClass>
</Associations>
</PricedOffer>
</AirlineOffer>
<AirlineOffer RequestedDateInd="true">
<OfferID Owner="BA">OFFER2</OfferID>
<TotalPrice>
<SimpleCurrencyPrice Code="GBP">129.50</SimpleCurrencyPrice>
</TotalPrice>
<PricedOffer>
<OfferPrice OfferItemID="1">
<RequestedDate>
<PriceDetail>
<TotalAmount>
<SimpleCurrencyPrice Code="GBP">129.50</SimpleCurrencyPrice>
</TotalAmount>
<BaseAmount Code="GBP">84.00</BaseAmount>
<Taxes>
<Total Code="GBP">45.50</Total>
</Taxes>
</PriceDetail>
<Associations>
<AssociatedTraveler>
<TravelerReferences>SH1</TravelerReferences>
</AssociatedTraveler>
</Associations>
</RequestedDate>
</OfferPrice>
<Associations>
<ApplicableFlight>
<FlightSegmentReference ref="BA2765">
<ClassOfService>
<Code>O</Code>
<MarketingName>Euro Traveller</MarketingName>
</ClassOfService>
</FlightSegmentReference>
</ApplicableFlight>
<PriceClass>
<PriceClassReference>Plus</PriceClassReference>
</PriceClass>
</Associations>
<Associations>
<ApplicableFlight>
<FlightSegmentReference ref="BA2764">
<ClassOfService>
<Code>Q</Code>
<MarketingName>Euro Traveller</MarketingName>
</ClassOfService>
</FlightSegmentReference>
</ApplicableFlight>
<PriceClass>
<PriceClassReference>Plus</PriceClassReference>
</PriceClass>
</Associations>
</PricedOffer>
</AirlineOffer>
</AirlineOffers>
【问题讨论】:
-
价格和OfferID与所选航段有什么关系?价格代码似乎在同一个
元素中,但我根本没有看到 OfferId 是如何相关的。
标签: xml vb.net linq linq-to-xml