title: How to read data with pagination from large xml file using c#
body: <p>I want to read data from <code>XML</code> file but i do not want to read all data and then sort and filter. basically i do not want to load all <code>XML</code> data into memory rather want to read small amount of data by pagination.</p>
  
  <p>we often read data from database with pagination and same way i want to read data from xml file with pagination. so tell me what would be the best class which i can use to do it.</p>
  
  <h2>My xml data look like:</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Root&gt;
    &lt;Orders&gt;
      &lt;OrderID&gt;10248&lt;/OrderID&gt;
      &lt;CustomerID&gt;VINET&lt;/CustomerID&gt;
      &lt;EmployeeID&gt;5&lt;/EmployeeID&gt;
      &lt;OrderDate&gt;1996-07-04T00:00:00&lt;/OrderDate&gt;
      &lt;RequiredDate&gt;1996-08-01T00:00:00&lt;/RequiredDate&gt;
      &lt;ShippedDate&gt;1996-07-16T00:00:00&lt;/ShippedDate&gt;
      &lt;ShipVia&gt;3&lt;/ShipVia&gt;
      &lt;Freight&gt;32.3800&lt;/Freight&gt;
      &lt;ShipName&gt;Vins et alcools Chevalier&lt;/ShipName&gt;
      &lt;ShipAddress&gt;59 rue de l'Abbaye&lt;/ShipAddress&gt;
      &lt;ShipCity&gt;Reims&lt;/ShipCity&gt;
      &lt;ShipPostalCode&gt;51100&lt;/ShipPostalCode&gt;
      &lt;ShipCountry&gt;France&lt;/ShipCountry&gt;
    &lt;/Orders&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <h2>now reading like this way with LINQ</h2>
  
  <pre><code>XDocument document = XDocument.Load(@"c:\users\WindowsFormsApplication5\Orders.xml");
  var query = from r in document.Descendants("Orders")
              select new
              {
                  OrderID = r.Element("OrderID").Value,
                  CustomerID = r.Element("CustomerID").Value,
                  EmployeeID = r.Element("EmployeeID").Value,
              };
  
  //setup query result ordering,
  //assume we have variable to determine ordering mode : bool isDesc = true/false
  if (isDesc) query = query.OrderByDescending(o =&gt; o.OrderID);
  else query = query.OrderBy(o =&gt; o.OrderID);
  
  //setup pagination, 
  //f.e displaying result for page 2 where each page displays 100 data
  var page = 2;
  var pageSize = 100;
  query = query.Skip(page - 1*pageSize).Take(pageSize);
  
  //execute the query to get the actual result
  var items = query.ToList();
  </code></pre>
  
  <p>If anyone see my above code then must notice the way I am reading data from <code>XML</code> file. It load all data into memory but I suppose I want to read 10 data at time then just will load 10 data in memory not all.</p>
  
  <p>Above coding approach will not be good if there is 10,000,000 records in <code>XML</code> file. So, what would be best way to read large <code>XML</code> file partly with pagination like concept.</p>