XNode.ToString XNode.ToString XNode.ToString Method

Definition

Returns the XML for this node, optionally disabling formatting.

Overloads

ToString() ToString() ToString()

Returns the indented XML for this node.

ToString(SaveOptions) ToString(SaveOptions) ToString(SaveOptions)

Returns the XML for this node, optionally disabling formatting.

ToString() ToString() ToString()

Returns the indented XML for this node.

public:
 override System::String ^ ToString();
public override string ToString ();
Public Overrides Function ToString () As String
Returns

A String containing the indented XML.

Examples

The following example uses this method to retrieve indented XML.

XElement xmlTree = new XElement("Root",  
    new XElement("Child1", 1)  
);  
Console.WriteLine(xmlTree);  
Dim xmlTree As XElement = _   
        <Root>  
            <Child1>1</Child1>  
        </Root>  

Console.WriteLine(xmlTree)  

This example produces the following output:

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

ToString(SaveOptions) ToString(SaveOptions) ToString(SaveOptions)

Returns the XML for this node, optionally disabling formatting.

public:
 System::String ^ ToString(System::Xml::Linq::SaveOptions options);
public string ToString (System.Xml.Linq.SaveOptions options);
Public Function ToString (options As SaveOptions) As String
Parameters
options
SaveOptions SaveOptions 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.

XElement root = XElement.Parse("<Root><Child/></Root>");  
Console.WriteLine(root.ToString(SaveOptions.DisableFormatting));  
Console.WriteLine("---");  
Console.WriteLine(root.ToString(SaveOptions.None));  
Dim root As XElement = <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>  

Applies to