Elias Wick
Elias Wick

Reputation: 493

How to modify the default indent value when creating an XML file?

I have been looking at different methods for creating an XML document using: XmlDocument, XDocument and XmlWriter. It seems like I have to use XmlWriterSettings along with XmlWriter in order to specify the Indent and IndentChars.

This MSDN Article specifies that the default IndentChars value is Two spaces.

My question: Is it possible to save an XML file using XmlDocument or XDocument where I can specify the indent value for the saved XML file?

If it is possible to do so without using XmlWriter, can someone provide an example or documentation?

Upvotes: 0

Views: 150

Answers (1)

Anton
Anton

Reputation: 851

Update: Sorry, I didn't read clearly your question. No, it is not possible. If you want to specify IdentChars, you should create XmlTextWriter

    var xmlDoc = new XmlDocument();

    // your logic 


    using (var writer = new XmlTextWriter("filename.xml")) {
        writer.Indentation = 1;
        writer.IndentChar = ' ';

        xmlDoc.Save(writer);
    }

Upvotes: 1

Related Questions