I am trying to format an XML page in C# per the request of client. Below is what I currently create in XML
<?xml version="1.0" encoding="utf-8"?>
<!--This is to write the connection strings, text file location, and report destination.-->
<AdminPaths Name="sqlConnection1" connectionString="asdf">
<TextPath>
<Key Value="Test3" xmlns="Path" />
</TextPath>
</AdminPaths>
This is what I would like to have:
<?xml version="1.0" encoding="utf-8"?>
<!--This is to write the connection string, text file location, and report destination.-->
<AdminPaths>
<Name="sqlConnection1" connectionString="asdf">
</AdminPaths>
<TextPath>
< Key="Path" Value="Test3">
< Key="Report" Value="Test2">
</TextPath>
Here is the code I am currently using:
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.");
writer.WriteStartElement("AdminPaths");
writer.WriteAttributeString("Name", "sqlConnection1");
writer.WriteAttributeString("connectionString", "asdf");
writer.WriteStartElement("TextPath");
writer.WriteStartElement("Key", "Path");
writer.WriteAttributeString("Value", "Test3");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
I have tried using writer.WriteEndElement(); after the writeAttributeString to start but I receive an error that states "Make sure that the ConformanceLevel setting is set to ConformanceLevel.Fragment or ConformanceLevel.Auto if you want to write an XML fragment." I believe that is not what I want to do? Any help would be appreciated.
thanks.