title: XML writer not including end tag
body: <p>Can anyone tell me why my XML writer is not writing out end tags when they ate like this: <code>/ &gt;</code></p>
  
  <p>What I am doing is reading an xml file and then writing it to a new file, and if certain elements are found I execute some code, and then override the elements with new ones. The whole purpose is to copy almost all of the xml in the first document except when it finds sspecific elements it needs to execute different code that will in turn output its new element that the writer adds. So far it is almost working properly, except for the end tags.</p>
  
  <p>Here is a snippet of what it is supposed to look like(difference examples noted with asterisks):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;ItemGroup Label="ProjectConfigurations"&gt;
      &lt;ProjectConfiguration Include="Debug|Win32"&gt;
        &lt;Configuration&gt;Debug&lt;/Configuration&gt;
        &lt;Platform&gt;Win32&lt;/Platform&gt;
      &lt;/ProjectConfiguration&gt;
      &lt;ProjectConfiguration Include="Release|Win32"&gt;
        &lt;Configuration&gt;Release&lt;/Configuration&gt;
        &lt;Platform&gt;Win32&lt;/Platform&gt;
      &lt;/ProjectConfiguration&gt;
    &lt;/ItemGroup&gt;
    &lt;PropertyGroup Label="Globals"&gt;
      &lt;ProjectGuid&gt;{57900E99-A405-49F4-83B2-0254117D041B}&lt;/ProjectGuid&gt;
      &lt;Keyword&gt;Win32Proj&lt;/Keyword&gt;
      &lt;RootNamespace&gt;libprojex&lt;/RootNamespace&gt;
    &lt;/PropertyGroup&gt;
    &lt;Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" **/&gt;**
    &lt;PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"&gt;
      &lt;ConfigurationType&gt;DynamicLibrary&lt;/ConfigurationType&gt;
      &lt;UseDebugLibraries&gt;true&lt;/UseDebugLibraries&gt;
      &lt;CharacterSet&gt;MultiByte&lt;/CharacterSet&gt;
      **&lt;PlatformToolset&gt;v110&lt;/PlatformToolset&gt;**
    &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>Here is my output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;ItemGroup Label="ProjectConfigurations"&gt;
      &lt;ProjectConfiguration Include="Debug|Win32"&gt;
        &lt;Configuration&gt;Debug&lt;/Configuration&gt;
        &lt;Platform&gt;Win32&lt;/Platform&gt;
      &lt;/ProjectConfiguration&gt;
      &lt;ProjectConfiguration Include="Release|Win32"&gt;
        &lt;Configuration&gt;Release&lt;/Configuration&gt;
        &lt;Platform&gt;Win32&lt;/Platform&gt;
      &lt;/ProjectConfiguration&gt;
    &lt;/ItemGroup&gt;
    &lt;PropertyGroup Label="Globals"&gt;
      &lt;ProjectGuid&gt;{57900E99-A405-49F4-83B2-0254117D041B}&lt;/ProjectGuid&gt;
      &lt;Keyword&gt;Win32Proj&lt;/Keyword&gt;
      &lt;RootNamespace&gt;libprojex&lt;/RootNamespace&gt;
    &lt;/PropertyGroup&gt;
    &lt;Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"&gt;
      &lt;PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"&gt;
        &lt;ConfigurationType&gt;DynamicLibrary&lt;/ConfigurationType&gt;
        &lt;UseDebugLibraries&gt;true&lt;/UseDebugLibraries&gt;
        &lt;CharacterSet&gt;MultiByte&lt;/CharacterSet&gt;
      &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>These are just short excerpts. They continue on throughout the document. If you notice lines that end with <code>/&gt;</code> , it will not add them to the writer properly. Also this line is missing from the output <code>&lt;PlatformToolset&gt;v110&lt;/PlatformToolset&gt;</code></p>
  
  <p>I have included some code to show how I am achieving this:</p>
  
  <pre><code>string vcName = Path.GetFileName(textBox1.Text);
  string vcProj = Path.Combine(baseDir, vcName);
  
  using (XmlReader reader = XmlReader.Create(textBox1.Text))
  {
      XmlWriterSettings settings = new XmlWriterSettings();
      settings.ConformanceLevel = ConformanceLevel.Auto;
      settings.Indent = true;
      settings.CloseOutput = false;
      string nameSpace = "http://schemas.microsoft.com/developer/msbuild/2003";
      using (XmlWriter writer = XmlWriter.Create(vcProj, settings))
      {
  
          while (reader.Read())
          {
              switch (reader.NodeType)
              {
                  case XmlNodeType.Element:
  
                     if (reader.Name == "ClInclude")
                      {
                          //execute code here- omitted for example
                          writer.WriteStartElement(reader.Name, nameSpace);
                          writer.WriteAttributeString("Include", "include/" + filename);
                          writer.WriteEndElement();
  
                      }
                      else if (reader.Name == "ClCompile" &amp;&amp; reader.HasAttributes)
                      {
                          //execute code here- omitted for example
                          writer.WriteStartElement(reader.Name, nameSpace);
                          writer.WriteAttributeString("Include", "src/" + filename);
                          writer.WriteEndElement();
  
                      } 
                     else
                      {
                          writer.WriteStartElement(reader.Name, nameSpace);
                          writer.WriteAttributes(reader, true);
                      }
  
                      break;
  
                  case XmlNodeType.Text:
                      writer.WriteString(reader.Value);
                      break;
                  case XmlNodeType.XmlDeclaration:
                  case XmlNodeType.ProcessingInstruction:
                      writer.WriteProcessingInstruction(reader.Name, reader.Value);
                      break;
                  case XmlNodeType.Comment:
                      writer.WriteComment(reader.Value);
                      break;
                  case XmlNodeType.Attribute:
                      writer.WriteAttributes(reader, true);
                      break;
                  case XmlNodeType.EntityReference:
                      writer.WriteEntityRef(reader.Value);
                      break;
                 case XmlNodeType.EndElement:
                      writer.WriteFullEndElement();
                      break;
  
                  }
          }
  
      }
  </code></pre>
  
  <p>Can anyone tell me why I am having these issues, is it that it is somehow ignoring invalid XML?</p>