Indentation and new line command for XMLwriter in C#
Use a XmlTextWriter instead of XmlWriter and then set the Indentation properties. Example string filename = “MyFile.xml”; using (FileStream fileStream = new FileStream(filename, FileMode.Create)) using (StreamWriter sw = new StreamWriter(fileStream)) using (XmlTextWriter xmlWriter = new XmlTextWriter(sw)) { xmlWriter.Formatting = Formatting.Indented; xmlWriter.Indentation = 4; // … Write elements } Following @jumbo comment, this could also be … Read more