I am trying to add one XElement to an XML file where element is already present in a specific format(see the line 2 where space is present before the Student element), however when i add the Xelement, how could i add a space before the Xelement ? See line 5 in below images for difference of space for formatting ?
Creating the Tag here:
XElement newStudent = new XElement("Student");
newStudent.SetAttributeValue("Name", "jhonny");
newStudent.Add(new XText("\n "));
XElement stuSetting = new XElement("Subject");
stuSetting.SetAttributeValue("Name", "C#");
stuSetting.SetAttributeValue("Mark", "95");
newStudent.Add(stuSetting);
newStudent.Add(new XText("\n "));
Add in the existing file by loading it using XDocument:
StudentsXmlFile.Element("Students").Add(newStudent);
StudentsXmlFile.Element("Students").Add(new XText("\n"));
Currently Getting output: