Share via


XStreamingElement.ToString 方法

定义

返回此流元素的 XML,还可以选择禁用格式设置。

重载

ToString()

返回此流元素的格式设置(缩进)XML。

ToString(SaveOptions)

返回此流元素的 XML,还可以选择禁用格式设置。

注解

请注意,调试使用 XStreamingElement的程序时,显示 对象的值会导致调用其 ToString 方法。 这会导致 XML 序列化。 如果流式处理元素查询的语义使得流式处理元素只能流式传输一次,这可能会导致调试体验中出现不良行为。

ToString()

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

返回此流元素的格式设置(缩进)XML。

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

返回

包含缩进 XML 的 String

示例

以下示例演示 的两种 ToString用法。 第一个用法会保留空白。 第二个使用格式序列化 XStreamingElement

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());
Dim srcTree As XElement = _
    <Root>
        <Child>1</Child>
        <Child>2</Child>
        <Child>3</Child>
        <Child>4</Child>
        <Child>5</Child>
    </Root>

Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot", _
                        From el In srcTree.Elements() _
                        Where el.Value = 3 _
                        Select <DifferentChild><%= el.Value %></DifferentChild> _
                    )

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

该示例产生下面的输出:

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

注解

请注意,调试使用 XStreamingElement的程序时,显示 对象的值会导致调用其 ToString 方法。 这会导致 XML 序列化。 如果流式处理元素查询的语义使得流式处理元素只能流式传输一次,这可能会导致调试体验中出现不良行为。

另请参阅

适用于

ToString(SaveOptions)

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

返回此流元素的 XML,还可以选择禁用格式设置。

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

指定格式设置行为的 SaveOptions

返回

包含 XML 的 String

示例

以下示例演示 的两种 ToString用法。 第一个用法会保留空白。 第二个使用格式序列化 XStreamingElement

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());
Dim srcTree As XElement = _
    <Root>
        <Child>1</Child>
        <Child>2</Child>
        <Child>3</Child>
        <Child>4</Child>
        <Child>5</Child>
    </Root>

Dim dstTree As XStreamingElement = New XStreamingElement("NewRoot", _
                        From el In srcTree.Elements() _
                        Where el.Value = 3 _
                        Select <DifferentChild><%= el.Value %></DifferentChild> _
                    )

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

该示例产生下面的输出:

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

注解

请注意,调试使用 XStreamingElement的程序时,显示 对象的值会导致调用其 ToString 方法。 这会导致 XML 序列化。 如果流式处理元素查询的语义使得流式处理元素只能流式传输一次,这可能会导致调试体验中出现不良行为。

另请参阅

适用于