XmlDocument.PreserveWhitespace Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets or sets a value indicating whether to preserve white space in element content.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

member PreserveWhitespace : bool with get, set

Property Value

Type: System.Boolean

true to preserve white space; otherwise false. The default is false.

This property determines how white space is handled during the load and save process.

If PreserveWhitespace is true before Load or LoadXml is called, white space nodes are preserved; otherwise, if this property is false, significant white space is preserved, white space is not.

If PreserveWhitespace is true before Save is called, white space in the document is preserved in the output; otherwise, if this property is false, XmlDocument auto-indents the output.

This method is a Microsoft extension to the Document Object Model (DOM).

The following example shows how to strip white space from a file.

No code example is currently available or this language may not be supported.

The example uses the file book.xml as input.

<!--sample XML fragment-->
<book genre='novel' ISBN='1-861003-78' misc='sale-item'>
  <title>The Handmaid's Tale</title>

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top