Search This Blog

Tuesday, July 2, 2013

Get Descending order all records from XML file by linq

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_desending_order();
     
    }

    private void get_desending_order()
    {
        XElement xelement = XElement.Load(Server.MapPath("~/xml/hotel.xml"));
        foreach (XElement xele in xelement.Descendants("Price"))
        {
            Response.Write("</br>");
            Response.Write((string)xele);
        }

    }
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:
101
127
127
139
158
176
223
295
316
139
148
153
278
399
160
186
207

No comments :