<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sorted Bits &#187; XML</title>
	<atom:link href="http://www.sortedbits.com/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sortedbits.com</link>
	<description>objectiveC, C# and more interesting stuff</description>
	<lastBuildDate>Wed, 04 Jan 2012 10:11:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Reading big XML file with C# XmlReader</title>
		<link>http://www.sortedbits.com/reading-big-xml-file-with-c-xmlreader/</link>
		<comments>http://www.sortedbits.com/reading-big-xml-file-with-c-xmlreader/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 21:27:35 +0000</pubDate>
		<dc:creator>Wim</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.depl0y.com/?p=524</guid>
		<description><![CDATA[Today I needed to parse a LARGE (1.9GB) XML file and extract some information from it. Loading it in a XmlDocument (my favorite .NET way of handling XML) wasn&#8217;t really a possibility, because that would cause Out of Memory errors the minute I would try it. I [...]]]></description>
			<content:encoded><![CDATA[<p>Today I needed to parse a <strong>LARGE</strong> (1.9GB) XML file and extract some information from it. Loading it in a XmlDocument (my favorite .NET way of handling XML) wasn&#8217;t really a possibility, because that would cause Out of Memory errors the minute I would try it.</p>
<p>I am using a XmlReader for this and I noticed that there arent really many usable examples on the internet about this, so here is just a small example I created to show how you could read a RSS feed.</p>
<p>Sample after the break&#8230;<span id="more-524"></span></p>
<pre class="syntax c">// File to open up, can be an URL too
string XmlFileUrl = @&quot;c:feed.xml&quot;;
using (XmlReader reader = new XmlTextReader(XmlFileUrl))
{
	// Initialize a list for storage of the items
	List items = new List();
	// boolean to see if a node was opened before
	bool openItem = false;
	RssItem item = new RssItem();

	// Loop the reader, till it cant read anymore
	while (reader.Read())
	{
		// An object with the type Element was found.
		if (reader.NodeType == XmlNodeType.Element)
		{
			// Check name of the node and write the contents in the object accordingly.
			if (reader.Name == &quot;item&quot;)
			{
				item = new RssItem();
				openItem = true;
			}
			else if (reader.Name == &quot;title&quot; &amp;amp;&amp;amp; openItem)
				item.title = reader.ReadElementContentAsString();
			else if (reader.Name == &quot;link&quot; &amp;amp;&amp;amp; openItem)
				item.link = reader.ReadElementContentAsString();
			else if (reader.Name == &quot;description&quot; &amp;amp;&amp;amp; openItem)
				item.description = reader.ReadElementContentAsString();
		}
		// EndElement was found, check if it is named item, if it is, store the object in the list and set openItem to false.
		else if (reader.NodeType == XmlNodeType.EndElement &amp;amp;&amp;amp; reader.Name == &quot;item&quot; &amp;amp;&amp;amp; openItem)
		{
			openItem = false;
			items.Add(item);
		}
	}
}</pre>
<p>The <strong>RssItem</strong> class I created is just a simple class containing a couple of properties:</p>
<pre class="syntax c">public class RssItem
{
	public string title { get; set; }
	public string pubDate { get; set; }
	public string link { get; set; }
	public string description { get; set; }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sortedbits.com/reading-big-xml-file-with-c-xmlreader/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

