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 appropraite due to the size of the XML file. Instead some sort of streaming XML approach may be prefferable.

But XLINQ doesnt offer this facility straight out of the box, but with a bit of trickery we can get a XMLReader to do this streaming for us. Lets see an example shall we.


Thats the standard XLINQ query, but we still need to use an XmlReader to do the streaming, so lets see that part, its simply as shown below


And thats 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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s