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_other_element_result();
}
private void get_other_element_result()
{
XElement xelement = XElement.Load(Server.MapPath("~/xml/hotel.xml"));
var Hotel = from hname in xelement.Elements("Hotel")
where (int)xelement.Element("Hotel").Element("Code") == (int)hname.Element("RoomRates").Element("HotelCode")
select hname;
Console.WriteLine("Details of Hotel Name:");
foreach (XElement xele in Hotel)
Response.Write(xele.Element("Name") + "</br>" + xele.Element("Code") + "</br>" + xele.Element("RoomRates").Element("Price") + "</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:
Le Marly
101
20054
101
No comments :
Post a Comment