XStreamingElement.ToString Method

Definition

Returns the XML for this streaming element, optionally disabling formatting.

Overloads

ToString()

Returns the formatted (indented) XML for this streaming element.

ToString(SaveOptions)

Returns the XML for this streaming element, optionally disabling formatting.

Remarks

Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. This causes the XML to be serialized. If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.

ToString()

Source:
XStreamingElement.cs
Source:
XStreamingElement.cs
Source:
XStreamingElement.cs

Returns the formatted (indented) XML for this streaming element.

C#
public override string ToString();

Returns

A String containing the indented XML.

Examples

The following example shows two uses of ToString. The first use preserves white space. The second one serializes the XStreamingElement with formatting.

C#
XElement srcTree = new XElement("Root",
                       new XElement("Child", 1),
                       new XElement("Child", 2),
                       new XElement("Child", 3),
                       new XElement("Child", 4),
                       new XElement("Child", 5)
                   );

XStreamingElement dstTree = new XStreamingElement("NewRoot",
                        from el in srcTree.Elements()
                        where (int)el == 3
                        select new XElement("DifferentChild", (int)el)
                    );

Console.WriteLine(dstTree.ToString(SaveOptions.DisableFormatting));
Console.WriteLine("------");
Console.WriteLine(dstTree.ToString());

This example produces the following output:

<NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<NewRoot>
  <DifferentChild>3</DifferentChild>
</NewRoot>

Remarks

Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. This causes the XML to be serialized. If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.

See also

Applies to

.NET 10 e altre versioni
Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

ToString(SaveOptions)

Source:
XStreamingElement.cs
Source:
XStreamingElement.cs
Source:
XStreamingElement.cs

Returns the XML for this streaming element, optionally disabling formatting.

C#
public string ToString(System.Xml.Linq.SaveOptions options);

Parameters

options
SaveOptions

A SaveOptions that specifies formatting behavior.

Returns

A String containing the XML.

Examples

The following example shows two uses of ToString. The first use preserves white space. The second one serializes the XStreamingElement with formatting.

C#
XElement srcTree = new XElement("Root",
                       new XElement("Child", 1),
                       new XElement("Child", 2),
                       new XElement("Child", 3),
                       new XElement("Child", 4),
                       new XElement("Child", 5)
                   );

XStreamingElement dstTree = new XStreamingElement("NewRoot",
                        from el in srcTree.Elements()
                        where (int)el == 3
                        select new XElement("DifferentChild", (int)el)
                    );

Console.WriteLine(dstTree.ToString(SaveOptions.DisableFormatting));
Console.WriteLine("------");
Console.WriteLine(dstTree.ToString());

This example produces the following output:

<NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<NewRoot>
  <DifferentChild>3</DifferentChild>
</NewRoot>

Remarks

Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. This causes the XML to be serialized. If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.

See also

Applies to

.NET 10 e altre versioni
Prodotto Versioni
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0