Q:

C# Split Xml with the count

I have a large xml and I need to split it to smaller one. 

A:

With MoreLINQ (available from NuGet) you can split orders into batches, and then build new documents from batches:
XDocument xdoc = XDocument.Load("orders.xml");
int batchSize = 2;
int batchIndex = 0; 

foreach(var orders in xdoc.Descendants("order").Batch(batchSize))
{
    XDocument doc = new XDocument(new XElement("orders", orders));
    doc.Save(String.Format("orders-{0}.xml", batchIndex++));
}

This will create new documents, each will contain batchSize orders inside (well, last one can contain less orders). Orders will be placed under <orders> root tag.

You can even do all in single query
xdoc.Descendants("order").Batch(batchSize)
    .Select((orders, index) => new { orders, index })
    .ForEach(batch => {
        XDocument doc = new XDocument(new XElement("orders", batch.orders));
        doc.Save(String.Format("orders-{0}.xml", batch.index));
    });

