XElement.Save Method (TextWriter)

Serialize this element to a TextWriter.

Namespace:  System.Xml.Linq
Assemblies:   System.Xml.Linq (in System.Xml.Linq.dll)
  System.Xml.XDocument (in System.Xml.XDocument.dll)

member Save : 
        textWriter:TextWriter -> unit

Parameters

textWriter
Type: System.IO.TextWriter

A TextWriter that the XElement will be written to.

The serialized XML will be indented. All insignificant white space will be removed, and additional white space will be added so that the XML will be properly indented. The behavior of this method is that white space will not be preserved.

If you want to control white space, use the overload of Save that allows you to specify SaveOptions as a parameter. For more information, see Preserving White Space while Loading or Parsing XML and Preserving White Space While Serializing.

The following example creates an XElement, saves the document to a StringWriter, and then prints the string to the console.

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

This example produces the following output:

<?xml version="1.0" encoding="utf-16"?>
<Root>
  <Child> Text </Child>
</Root>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft