title: XmlElement InnerText property
body: <p>I'm delving into the world of XmlDocument building and thought I'd try to re-build (at least, in part) the Desktop tree given by Microsoft's program UISpy.</p>
  
  <p>So far I am able to grab a child of the desktop and write that to a XML document, and then grab each child of that and write those to an XML document.</p>
  
  <p>So far the code looks like this...</p>
  
  <pre><code>using System.Windows.Automation;
  using System.Xml;
  
  namespace MyTestApplication
  {
      internal class TestXmlStuff
      {
          public static void Main(string[] args)
          {
              XmlDocument xDocument = new XmlDocument();
              AutomationElement rootElement = AutomationElement.RootElement;
              TreeWalker treeWalker = TreeWalker.ContentViewWalker;
  
              XmlNode rootXmlElement = xDocument.AppendChild(xDocument.CreateElement("Desktop"));
              AutomationElement autoElement = rootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "GitHub"));
              string name = autoElement.Current.Name;
  
              while (autoElement != null)
              {
                  string lct = autoElement.Current.LocalizedControlType.Replace(" ", "");
                  lct = (lct.Equals("") ? "Cusotm" : lct);
                  XmlElement temp = (XmlElement)rootXmlElement.AppendChild(xDocument.CreateElement(lct));
                  //temp.InnerText = lct;
                  string outerXML = temp.OuterXml;
                  rootXmlElement = temp;
                  autoElement = treeWalker.GetNextSibling(autoElement);
              }
          }   
      }
  }
  </code></pre>
  
  <p>...and the resulting XML file...</p>
  
  <p><a href="https://i.stack.imgur.com/Fv7zD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fv7zD.png" alt="Test XML File"></a></p>
  
  <p>Now, when I add a line to change the InnerText Property of each XML element, like <code>temp.InnerText = lct</code> I get an oddly formated XML file.</p>
  
  <p><a href="https://i.stack.imgur.com/CORPP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CORPP.png" alt="enter image description here"></a></p>
  
  <p>What I expected from this was that each InnerText would be on the same line as the start and end tags of the XML element, but instead all but the last element's InnerText is located on a new line.</p>
  
  <p>So my question is, why is that? Is there something else I could be doing with my XML elements to have their InnerText appear on the same line?</p>