title: How to change number of characters used for indentation when writing XML with XDocument
body: <p>I am trying to change the default indentation of XDocument from 2 to 3, but I'm not quite sure how to proceed.  How can this be done?</p>
  
  <p>I'm familiar with <code>XmlTextWriter</code> and have used code as such:</p>
  
  <pre><code>using System.Xml;
  
  namespace ConsoleApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              string destinationFile = "C:\myPath\results.xml";
              XmlTextWriter writer = new XmlTextWriter(destinationFile, null);
              writer.Indentation = 3;
              writer.WriteStartDocument();
  
              // Add elements, etc
  
              writer.WriteEndDocument();
              writer.Close();
          }
      }
  }
  </code></pre>
  
  <p>For another project I used <code>XDocument</code> because it works better for my implementation similar to this:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Xml.Linq;
  using System.Xml;
  using System.Text;
  
  namespace ConsoleApp
  {
      class Program
      {
          static void Main(string[] args)
          {
              // Source file has indentation of 3
              string sourceFile = @"C:\myPath\source.xml";
              string destinationFile = @"C:\myPath\results.xml";
  
              List&lt;XElement&gt; devices = new List&lt;XElement&gt;();
  
              XDocument template = XDocument.Load(sourceFile);        
  
              // Add elements, etc
  
              template.Save(destinationFile);
          }
      }
  }
  </code></pre>