Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing a range of elements from any point in an IEnumerable

I have this method:

private IEnumerable<XElement> ReadTransactions(string file_name)
    {
        using (var reader = XmlReader.Create(file_name + ".xml"))
        {
            while (reader.ReadToFollowing("transaction", "urn:namepsaceUri"))
            {
                using (var subtree = reader.ReadSubtree())
                {
                    yield return XElement.Load(subtree);
                }
            }
        }
    }

This method reads from an XML file. However, I don't need all of the nodes in the XML file at same time.

I want to get them ten at a time.

I tried working with XPathSelectElements, but that gets all the nodes, and then I need to iterate through them.

So, is there a way to get the nodes from the XML file which are 40-50? I want to modify ReadTransactions - to have another input parameter (40 in this case), and instead of all the elements, it will return just 10?

like image 372
petko_stankoski Avatar asked Apr 30 '13 08:04

petko_stankoski


1 Answers

what about ElementAt

seems to me this is what you are looking for

like image 59
Paul Baxter Avatar answered Oct 06 '22 00:10

Paul Baxter