XNode.ToString 方法

定义

返回此节点的 XML,还可以选择禁用格式设置。Returns the XML for this node, optionally disabling formatting.

重载

ToString()

返回此节点的缩进 XML。Returns the indented XML for this node.

ToString(SaveOptions)

返回此节点的 XML,还可以选择禁用格式设置。Returns the XML for this node, optionally disabling formatting.

ToString()

返回此节点的缩进 XML。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

返回

包含缩进 XML 的 StringA String containing the indented XML.

示例

下面的示例使用此方法检索缩进的 XML。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)

返回此节点的 XML,还可以选择禁用格式设置。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

参数

options
SaveOptions

指定格式设置行为的 SaveOptionsA SaveOptions that specifies formatting behavior.

返回

包含 XML 的 StringA String containing the XML.

示例

下面的示例使用此方法检索未格式化和格式化的 XML。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>  

另请参阅

适用于