title: XStreamingElement as part of an XDocument
body: <p>I want to write a very large XML document, so <a href="https://msdn.microsoft.com/en-us/library/system.xml.linq.xstreamingelement(v=vs.110).aspx" rel="nofollow"><code>System.Xml.Linq.XStreamingDocument</code></a> seemed like the ideal solution.</p>
  
  <p>I thought I would be able to construct the <code>XDocument</code> to contain the <code>XStreamingDocument</code> and only when I call <code>Save()</code> would the tree be traversed and the enumerable be iterated.</p>
  
  <pre><code>public void WriteXml(IEnumerable&lt;string&gt; lotsOfStrings, TextWriter output)
  {
      var rootElement = new XElement("Root", 
         new XStreamingElement ("Strings", lotsOfStrings.Select(s =&gt; new XElement("Line", s))));
  
      var document = new XDocument(rootElement);
      document.Save(output);
  }
  </code></pre>
  
  <p>But this isn't the case. As soon as I add an <code>XStreamingElement</code> to a containing element, it iterates the enumerable and generates all of the elements.</p>
  
  <p>I intend this long element list to be nested several elements deep. Do I have to write the containing structure manually using an <code>XmlWriter</code> before calling <code>XStreamingElement.WriteTo()</code>? This would be a bit tedious and end up with me mixing paradigms (<code>XmlWriter</code> and <code>System.Xml.Linq</code>). It would seem to really limit the usefulness of <code>XStreamingElement</code>. </p>
  
  <p>Or am I missing some way of constructing a document that contains streamable elements?</p>