Results 1 to 6 of 6

Thread: [RESOLVED] XMLDocument.Save... Unindented :(

  1. #1

    Thread Starter
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Resolved [RESOLVED] XMLDocument.Save... Unindented :(

    Hi people, does anybody know if XMLDocument.Save method can save a XML file without any formatting (unindented and without CRLFs)?

    The reason for that is that XML files I work with are about 300Mb in size and indentation eats quite a lot of disk memory.

  2. #2
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: XMLDocument.Save... Unindented :(

    XmlDocument.Save doesn't have an option to omit the formatting. If you use XmlDocument.WriteTo you can use an XmlTextWriter which has a Formatting.None option.

    Code:
        Private Sub WriteXml(ByVal xDoc As XmlDocument)
            Dim writer As New XmlTextWriter("C:\Temp\unindented.xml", System.Text.Encoding.UTF8)
            writer.Formatting = Formatting.None
            xDoc.WriteTo(writer)
            writer.Flush()
            writer.Close()
        End Sub

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: XMLDocument.Save... Unindented :(

    yes it is possible to remove whitespace + indents:

    http://msdn.microsoft.com/en-us/library/z2w98a50.aspx

  4. #4
    Frenzied Member MattP's Avatar
    Join Date
    Dec 2008
    Location
    WY
    Posts
    1,227

    Re: XMLDocument.Save... Unindented :(

    Hmmm, not sure how I missed the Save overload that takes an XmlWriter. Thanks for the correction .paul.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: XMLDocument.Save... Unindented :(

    it wasn't a correction you just snicked your answer in before mine

  6. #6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width