Прочетете на английски Редактиране

Споделяне чрез


XNode.ToString Method

Definition

Returns the XML for this node, optionally disabling formatting.

Overloads

ToString()

Returns the indented XML for this node.

ToString(SaveOptions)

Returns the XML for this node, optionally disabling formatting.

ToString()

Source:
XNode.cs
Source:
XNode.cs
Source:
XNode.cs

Returns the indented XML for this node.

C#
public override string ToString();

Returns

A String containing the indented XML.

Examples

The following example uses this method to retrieve indented XML.

C#
XElement xmlTree = new XElement("Root",  
    new XElement("Child1", 1)  
);  
Console.WriteLine(xmlTree);  

This example produces the following output:

XML
<Root>  
  <Child1>1</Child1>  
</Root>  

See also

Applies to

.NET 10 и други версии
Продукт Версии
.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:
XNode.cs
Source:
XNode.cs
Source:
XNode.cs

Returns the XML for this node, 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 uses this method to retrieve unformatted and formatted XML.

C#
XElement root = XElement.Parse("<Root><Child/></Root>");  
Console.WriteLine(root.ToString(SaveOptions.DisableFormatting));  
Console.WriteLine("---");  
Console.WriteLine(root.ToString(SaveOptions.None));  

This example produces the following output:

<Root><Child /></Root>  
---  
<Root>  
  <Child />  
</Root>  

See also

Applies to

.NET 10 и други версии
Продукт Версии
.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