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

傳回

String,包含縮排的 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)

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

傳回

String,包含 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 序列化。 如果串流元素查詢的語意使得串流元素只能串流處理一次,這可能會造成偵錯體驗中不想要的行為。

另請參閱

適用於