Data Developer Center > Data Platform Development Forums > XML, System.Xml, MSXML and XmlLite > Xmldocument , save method & Original Format of Xml File

Proposed Answer Xmldocument , save method & Original Format of Xml File

  • Monday, January 21, 2008 11:48 AM
     
     

     

    I am getting XML file from other system.

     

    Using XmlDocument object i opened Xml file.

     

    After changes done to XmlDocument when i call save method of xmlDocument.

    After this i want to send XmlDocument file back to other system.

     

    Now problem begins when i call save method. It changes original format of Xml file, which is having properly indented.

     

    I tried with PreserveWhitespace = false, but did not helped.

     

    Thanks in advance.

All Replies

  • Monday, January 21, 2008 12:41 PM
     
     Proposed Answer

    Well you need PreserveWhitespace set to true if you want to preserve the formatting of the XML. Set that before you call the Load method.

  • Monday, January 21, 2008 10:34 PM
     
     Proposed Answer

    If you want the Save method to output your Xml with formatting, you should use the XmlDocument.Save(XmlWriter) overload. Use XmlWriter.Create(Stream, XmlWriterSettings) to create the XmlWriter instance, XmlWriterSettings to control the formatting.

     

    Code Block
    XmlWriterSettings settings = new XmlWriterSettings();
    settings.Indent = true;
    settings.OmitXmlDeclaration = true;
    settings.NewLineOnAttributes = true;

     

     

     

    • Proposed As Answer by peterg89 Tuesday, February 01, 2011 12:34 PM
    •