I think this is the XML that you want. I'm guessing, because the XML you state as your goal is not correctly formed.
<?xml version="1.0" encoding="utf-8"?>
<!--This is to write the connection strings, text file location, and report destination.-->
<AdminPaths>
<AdminPath Name="sqlConnection1" connectionString="asdf" />
<TextPath>
<Text Key="Path" Value="Test3" />
<Text Key="Report" Value="Test2" />
</TextPath>
</AdminPaths>
Basically, in your stated goal XML, you were trying to create 2 root nodes under the xml document, which is a no-no, unless you are willing to use ConformanceLevel.Fragment
or ConformanceLevel.Auto
and force this behavior.
The code for this would like the following:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create("C:\\Users\\fthompson11\\WebFile.xml",
settings);
writer.WriteStartDocument();
writer.WriteComment("This is to write the connection strings, text file location, and report destination.");
// the AdminPaths
writer.WriteStartElement("AdminPaths");
writer.WriteStartElement("AdminPath");
writer.WriteAttributeString("Name", "sqlConnection1");
writer.WriteAttributeString("connectionString", "asdf");
writer.WriteEndElement();
// the TextPath's
writer.WriteStartElement("TextPath");
writer.WriteStartElement("Text");
writer.WriteAttributeString("Key", "Path");
writer.WriteAttributeString("Value", "Test3");
writer.WriteEndElement();
writer.WriteStartElement("Text");
writer.WriteAttributeString("Key", "Report");
writer.WriteAttributeString("Value", "Test2");
writer.WriteEndElement();
writer.WriteEndElement(); // </AdminPaths>
writer.WriteEndDocument();
writer.Flush();
writer.Close();