<p>How can you do a streaming read on a large XML file that contains a xs:sequence just below root element, without loading the whole file into a XDocument instance in memory?</p>

[{'answer_id': 45484, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 0, 'selected': False, 'text': '<p>I think it\'s not possible if you want to use object model (i.e. XElement\\XDocument) to query XML. Obviously, you can\'t build XML objects tree without reading enough data. However you can use <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx" rel="nofollow noreferrer">XmlReader</a> class.</p>\n\n<blockquote>\n  <p>The XmlReader class reads XML data\n  from a stream or file. It provides\n  non-cached, forward-only, read-only\n  access to XML data.</p>\n</blockquote>\n'}, {'answer_id': 45487, 'author': 'bitbonk', 'author_id': 4227, 'author_profile': 'https://Stackoverflow.com/users/4227', 'pm_score': 0, 'selected': False, 'text': '<p>Heres is a howto: <a href="http://support.microsoft.com/kb/301228/en-us" rel="nofollow noreferrer">http://support.microsoft.com/kb/301228/en-us</a> Just remember that you should not use XmlTextReader but instead XmlReader in conjunction with XmlReader.Create</p>\n'}, {'answer_id': 45488, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m confused by the mention of the "xs:sequence" - this is a XML Schema element. </p>\n\n<p>Are you trying to open a large XML Schema file? Are you open a large XML file that is based on that schema? Or are you trying to open a large XML file and validate it at the same time?</p>\n\n<p>None of these situations should provide you with a problem using the standard XmlReader (or XmlValidatingReader).</p>\n\n<p>Reading XML with XMLReader: <a href="http://msdn.microsoft.com/en-us/library/9d83k261(VS.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/9d83k261(VS.80).aspx</a></p>\n'}, {'answer_id': 45493, 'author': 'Hirvox', 'author_id': 4674, 'author_profile': 'https://Stackoverflow.com/users/4674', 'pm_score': 4, 'selected': True, 'text': '<p>Going with a SAX-style element parser and the <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.aspx" rel="noreferrer">XmlTextReader</a> class created with <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspx" rel="noreferrer">XmlReader.Create</a> would be a good idea, yes. Here\'s a slightly-modified code example from <a href="http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c4221/" rel="noreferrer">CodeGuru</a>:</p>\n\n<pre><code>void ParseURL(string strUrl)\n{\n  try\n  {\n    using (var reader = XmlReader.Create(strUrl))\n    {\n      while (reader.Read())\n      {\n        switch (reader.NodeType)\n        {\n          case XmlNodeType.Element:\n            var attributes = new Hashtable();\n            var strURI = reader.NamespaceURI;\n            var strName = reader.Name;\n            if (reader.HasAttributes)\n            {\n              for (int i = 0; i &lt; reader.AttributeCount; i++)\n              {\n                reader.MoveToAttribute(i);\n                attributes.Add(reader.Name,reader.Value);\n              }\n            }\n            StartElement(strURI,strName,strName,attributes);\n            break;\n            //\n            //you can handle other cases here\n            //\n            //case XmlNodeType.EndElement:\n            // Todo\n            //case XmlNodeType.Text:\n            // Todo\n            default:\n            break;\n          }\n        }\n      }\n      catch (XmlException e)\n      {\n        Console.WriteLine("error occured: " + e.Message);\n      }\n    }\n  }\n}\n</code></pre>\n'}, {'answer_id': 45499, 'author': 'Simon Steele', 'author_id': 4591, 'author_profile': 'https://Stackoverflow.com/users/4591', 'pm_score': 0, 'selected': False, 'text': "<p>That code sample tries to turn XmlReader style code into SAX style code - if you're writing code from scratch I'd just use XmlReader as it was intended - Pull not Push.</p>\n"}, {'answer_id': 501922, 'author': 'danny', 'author_id': 61324, 'author_profile': 'https://Stackoverflow.com/users/61324', 'pm_score': 3, 'selected': False, 'text': "<p>I can't add a comment, since I just signed up but the code sample posted by Hirvox and currently selected as the answer has a bug in it. It should not have the <code>new</code> statement when using the static <code>Create</code> method.</p>\n\n<p>Current: </p>\n\n<pre><code>using (var reader = new XmlReader.Create(strUrl))\n</code></pre>\n\n<p>Fixed: </p>\n\n<pre><code>using (var reader = XmlReader.Create(strUrl))\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/45481', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4685/']