Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / XLINQ

How to Stream XLINQ

5.00/5 (1 vote)
17 Jun 2009CPOL 15.4K  
How to stream XLINQ

From time to time, when you are using XLINQ to query XML data, you may find that you are dealing with a very large XML file. Loading a very large XML file using the standard XLINQ Load() method may not be appropriate due to the size of the XML file. Instead, some sort of streaming XML approach may be preferable.

But XLINQ doesn't offer this facility straight out of the box, but with a bit of trickery, we can get an XMLReader to do this streaming for us. Let's see an example, shall we?

37374/stream12.png

That's the standard XLINQ query, but we still need to use an XmlReader to do the streaming, so let's see that part, it's simply as shown below:

37374/stream22.png

And that's it, its a simple as that. We can now query a large XML file using XLINQ and be safe in the knowledge that it will be streamed using an XmlReader and the Yield keyword.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)