Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ
I have following XML,
 
<HotelProduct PricingSource="System" InventorySource="System" ExternalDetailsObtained="false" Code="IAI06" Category="4R" InstantPurchase="false">
 <Description>Deluxe Guest Room</Description>
 <Supplier Type="Hotel" Code="LIAIS" City="WAS"/>
<InventoryDetails Status="Available">
<ExtendedInventoryDetails MaximumAvailable="3">
 <InventoryProduct Code="IAI06" City="WAS"/>
 </ExtendedInventoryDetails>
 </InventoryDetails>
 <PriceDetails PricingDuration="5" Price="765.00" IncludesBonusNights="false"/>
<DescriptiveItineraryText>
 <Text Heading="true">Check In: 3:00 pm</Text>
 <Text/>
 <Text>Hotel is situated in the heart of the capital city the hotel is</Text>
 <Text>close to all of the city's major attractions. Centrally located</Text>
 <Text>on New Jersey Avenue close to nearby dining and shopping.</Text>
 </DescriptiveItineraryText>
 <DurationDetails MinimumDuration="1" MaximumDuration="99"/>
<DateBands>
<DateBand EffectiveToDate="2012-11-26" EffectiveFromDate="2012-11-16">
 <Applicability SplitRates="true" BaseRates="false"/>
 <CheckOutDetails StandardCheckOutTime="12:00:00"/>
<MealOptions>
<MealOption Code="0">
 <Description>No Meals Included</Description>
 </MealOption>
 </MealOptions>
 </DateBand>
<DateBand EffectiveToDate="2013-02-10" EffectiveFromDate="2012-11-27">
 <Applicability SplitRates="true" BaseRates="false"/>
 <CheckOutDetails StandardCheckOutTime="12:00:00"/>
 </DateBand>
<DateBand EffectiveToDate="2013-02-25" EffectiveFromDate="2013-02-11">
 <Applicability SplitRates="true" BaseRates="false"/>
 <CheckOutDetails StandardCheckOutTime="12:00:00"/>
 </DateBand>
<DateBand EffectiveToDate="2013-02-27" EffectiveFromDate="2013-02-26">
 <Applicability SplitRates="true" BaseRates="false"/>
 <CheckOutDetails StandardCheckOutTime="12:00:00"/>
 </DateBand>
<DateBand EffectiveToDate="2013-03-17" EffectiveFromDate="2013-02-28">
 <Applicability SplitRates="true" BaseRates="false"/>
 <CheckOutDetails StandardCheckOutTime="12:00:00"/>
 </DateBand>
 </DateBands>
 </HotelProduct>
 

I wanted to get all values of text in descriptiveitinerarytext element and create a string builder.
 
I have tried following query in LINQ,
 

IEnumerable<string> textSegs = from seg in _hotel.Descendants("DescriptiveItineraryText")
from text in seg.Descendants("Text")
select (string)text;
 
string str = textSegs.Aggregate(new StringBuilder(), (sb, i) => sb.Append(i), sp => sp.ToString());
 
I have declared _hotel as XElement.
 
I am not getting expected result.
 
Any suggestion would be helpful.
 
Thanks
Posted 19-Nov-12 2:09am
Edited 19-Nov-12 2:58am
v2
Comments
n.podbielski at 19-Nov-12 9:39am
   
And what do you getting?
Darkjo at 20-Nov-12 7:56am
   
I've tried your code and I become this:
 
Check In: 3:00 pmHotel is situated in the heart of the capital city the hotel isclose to all of the city's major attractions. Centrally locatedon New Jersey Avenue close to nearby dining and shopping.
 
Is it not what you are expecting to have?
 
Maybe you're expecting this:
 
Check In: 3:00 pm
 
Hotel is situated in the heart of the capital city the hotel is
close to all of the city's major attractions. Centrally located
on New Jersey Avenue close to nearby dining and shopping.
 
If it is the case, try this:
 
string str = textSegs.Aggregate(new StringBuilder(), (sb, i) => sb.Append(i + "\n"), sp => sp.ToString());

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sarvesh Kumar Gupta 228
1 CHill60 200
2 Sergey Alexandrovich Kryukov 153
3 DamithSL 153
4 Peter Leow 145


Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid