this is my xml...
<CruiseProduct>
<ID>4091</ID>
<Name>MS ROYAL RUBY NILE CRUISE</Name>
<Description>
<p><br>In house music panel.<br>Safe deposit box.<br>All modern and high quality installation and amenities.<br><br><br><b>All inclusive formula</b><br>Breakfast open buffet<br>Lunch open buffet<br>dinner open buffet<br>From 11.00 AM till 23.00 HRS<br>Water (Small Bottle)<br>Soft drinks<br>Local beer (Served by glass)<br>Local wine (Only during lunch and dinner)</p><p><br><b><b>The Program includes:</b><br></b>♦ 07 nights’ accommodation on board of MS Royal Ruby or Similar based on Full Board<br>♦ Return airport transfers in Luxor using Shuttle services<br>♦ Guaranteed upgrade to Main / Middle deck cabins.<br>♦ Complimentary Luxor city tour<b><br><br><b>The Program excludes:</b><br></b>♦ Entry visa to Egypt<br>♦ Tips and personal expenses<br>♦ Any other items did not mentioned above</p><p><b><br></b></p><p><b>Attraction - Combo Light Package</b><br>Visit to the east Bank, Karnak and Luxor temples, Visit the Temple shared by two gods Sobek and Haeroris in Kom Ombo afternoon, Morning visit to High dam, Phila temple<br><b><br>Attraction - Combo Full Package Excursions</b><br>Visit to the East Bank, Karnak and Luxor temples, Visit the Temple shared by two gods Sobek and Haeroris in Kom Ombo afternoon, Visit Edfu Temple, Morning visit to High dam, Philae temple and unfinished obelisk, on return visits West bank, Hatsheput, Valley of the Kings, Memmon colossi Esna Temple<br><br><b>Attraction - Cruise Signature Program</b><br>Visit Dier-al-Madina + Habu Temple + Valley of the Nobles, Dendra Temple by bus + Temple of Hathor-Cript, Edfu OR Kom Ombo Temple (up to the customer) Kalabsha trip + Botanical Gardens + 01 hour felucca </p>
</Description>
<Ref>CMBRUB</Ref>
<Location>Luxor</Location>
<Images>
<Image>
<Name>MS Royal Ruby</Name>
<Description/>
<URL>
http://banks.digital-trip.co.uk/assets/images/packages/c228fa2c-18b1-4c93- 9edc-aa3409d07b7b.jpg
</URL>
</Image>
this my code ....
var product = from a in cruiseDoc.Descendants("CruiseProduct")
select new CProducts
{
cruise_Id = a.Element("ID").Value,
cruise_Name = a.Element("Name").Value,
cruise_description= a.Element("Description").Value,
// cruise_Imagerurl = a.Descendants("")
};
var newProduct = product.ToArray();
ViewBag.Lengths = newProduct;
I want to call for the imager URL element at once and assign its value in cruise_Imageurl variable. Hope your help
Now that we know you only want the first Image element, it's simple:
cruise_Imagerurl = a.Element("Images").Element("Image").Element("URL").Value
This assumes there always is at least one image, mind you. If that's not the case, you might want:
cruise_Imagerurl = (string) a.Elements("Images")
.Elements("Image")
.Elements("URL")
.FirstOrDefault()
See more on this question at Stackoverflow