Επεξεργασία

Κοινή χρήση μέσω


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.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
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>  

See also

Applies to

ToString(SaveOptions)

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

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

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.

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>  

See also

Applies to