語言

XStreamingElement.ToString 方法

定義

回傳此串流元素的 XML,並可選擇關閉格式化。

多載

名稱 Description
ToString()

回傳此串流元素格式化(縮排)的 XML。

ToString(SaveOptions)

回傳此串流元素的 XML,並可選擇關閉格式化。

備註

請注意,除錯使用 XStreamingElement的程式時,顯示物件的值會促使其 ToString 方法被呼叫。 這會使 XML 被序列化。 如果你的串流元素查詢的語意是該串流元素只能串流一次,可能會導致除錯體驗出現不良行為。

ToString()

來源:
XStreamingElement.cs
來源:
XStreamingElement.cs
來源:
XStreamingElement.cs
來源:
XStreamingElement.cs
來源:
XStreamingElement.cs

回傳此串流元素格式化(縮排)的 XML。

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

傳回

String A 包含縮排的 XML。

範例

以下範例展示了兩種 的 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)

來源:
XStreamingElement.cs
來源:
XStreamingElement.cs
來源:
XStreamingElement.cs
來源:
XStreamingElement.cs
來源:
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一個指定格式行為的 A。

傳回

String A 包含 XML 的 XML。

範例

以下範例展示了兩種 的 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 被序列化。 如果你的串流元素查詢的語意是該串流元素只能串流一次,可能會導致除錯體驗出現不良行為。

另請參閱

適用於