1

I have a XDocument that is formatted like this:

<tag1><innertag Name="sample">This is text</innertag></tag1>

After load and save it changes to the below format:

<tag1>
   <innertag Name="sample">This is text</innertag>
</tag1>

How do I retain the above format?

If I use SaveOptions during save, there is nil indent and the whole file is in a single line. I want the above format to be retained. Is it possible ?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Niveditha
  • 31
  • 2

1 Answers1

1

XDocument object has several .Save() method overloads, half of which take SaveOptions enum value as the second parameter. This enum probably has what you need:

public enum SaveOptions
{
    /// <summary>Format (indent) the XML while serializing.</summary>
    None,
    /// <summary>Preserve all insignificant white space while serializing.</summary>
    DisableFormatting,
    /// <summary>Remove the duplicate namespace declarations while serializing.</summary>
    OmitDuplicateNamespaces
}
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Robert Synoradzki
  • 1,766
  • 14
  • 20