using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
//***Add below class for XElement
using System.Xml;
using System.Text;
using System.Xml.Linq;
/*LINQ—language integrated query—introduces many extensions methods to the standard C# environment.
These methods work on Lists, arrays and collections that are not yet in memory.
*/
public partial class Linq : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
get_Specific_result();
}
private void get_Specific_result()
{
XElement xelement = XElement.Load(Server.MapPath("~/xml/hotel.xml"));
var Hotel = from hname in xelement.Elements("Hotel")
where (int)hname.Element("Code") < 1000
select hname;
Console.WriteLine("Details of Hotel Name:");
foreach (XElement xele in Hotel)
Response.Write(xele.Element("Name") + "</br>" + xele.Element("Code") + "</br>");
}
}
INPUT XML FILE:
<?xml version="1.0" encoding="utf-8"?>
<HotelRoomAvailability>
<Hotel>
<Code>20054</Code>
<Name>Le Marly</Name>
<Description />
<Address>Hamra, Main Street, Beirut, Lebanon.</Address>
<MainPic />
<CountryCode>282</CountryCode>
<DestCode>7</DestCode>
<CategoryCode>3</CategoryCode>
<MultiBookingBoardType>true</MultiBookingBoardType>
<ReferenceNB>7-20054</ReferenceNB>
<RoomRates>
<RoomPurchaseToken>720054124</RoomPurchaseToken>
<RoomCode>sgl</RoomCode>
<RoomType>Single Classic Room Bed and Breakfast</RoomType>
<Adults>1</Adults>
<Children>0</Children>
<Quantity>1</Quantity>
<Price>101</Price>
<CurrencyCode>USD</CurrencyCode>
<Type>Available</Type>
<OfferType />
<HotelCode>20054</HotelCode>
</RoomRates>
</Hotel>
<Hotel>
<Code>35</Code>
<Name>Charles</Name>
<Description />
<Address>Rustom Bacha Street, Ain El Mraysseh, Beirut</Address>
<MainPic />
<CountryCode>282</CountryCode>
<DestCode>7</DestCode>
<CategoryCode>3</CategoryCode>
<MultiBookingBoardType>true</MultiBookingBoardType>
<ReferenceNB>7-35</ReferenceNB>
<RoomRates>
<RoomPurchaseToken>73516</RoomPurchaseToken>
<RoomCode>sgl</RoomCode>
<RoomType>Single Standard Room Bed and Breakfast</RoomType>
<Adults>1</Adults>
<Children>0</Children>
<Quantity>1</Quantity>
<Price>127</Price>
<CurrencyCode>USD</CurrencyCode>
<Type>Available</Type>
<OfferType />
<HotelCode>35</HotelCode>
</RoomRates>
<RoomRates>
<RoomPurchaseToken>73517</RoomPurchaseToken>
<RoomCode>sgl</RoomCode>
<RoomType>Single Deluxe Room Bed and Breakfast</RoomType>
<Adults>1</Adults>
<Children>0</Children>
<Quantity>1</Quantity>
<Price>127</Price>
<CurrencyCode>USD</CurrencyCode>
<Type>Available</Type>
<OfferType />
<HotelCode>35</HotelCode>
</RoomRates>
</Hotel>
OUTPUT:
Charles
Bella Riva Suite
Alexandre
Duroy Hotel
Tamar Rotana
Golden Tulip De Ville
35
Bella Riva Suite
26
Alexandre
13
Duroy Hotel
39
Tamar Rotana
56
Golden Tulip De Ville
38
No comments :
Post a Comment