XStreamingElement.ToString 方法
定义
返回此流元素的 XML,还可以选择禁用格式设置。Returns the XML for this streaming element, optionally disabling formatting.
重载
| ToString() |
返回此流元素的格式设置(缩进)XML。Returns the formatted (indented) XML for this streaming element. |
| ToString(SaveOptions) |
返回此流元素的 XML,还可以选择禁用格式设置。Returns the XML for this streaming element, optionally disabling formatting. |
注解
请注意,在调试使用的程序时 XStreamingElement ,显示对象的值将导致 ToString 调用其方法。Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. 这将导致对 XML 进行序列化。This causes the XML to be serialized. 如果流式处理元素查询的语义使得流式处理元素只能流式传输一次,则这可能会导致在调试过程中出现意外的行为。If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.
ToString()
返回此流元素的格式设置(缩进)XML。Returns the formatted (indented) XML for this streaming element.
public:
override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
返回
包含缩进 XML 的 String。A String containing the indented XML.
示例
下面的示例演示了的两种用法 ToString 。The following example shows two uses of ToString. 第一次使用将保留空白。The first use preserves white space. 第二个序列化, XStreamingElement 并将设置为格式。The second one serializes the XStreamingElement with formatting.
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())
该示例产生下面的输出:This example produces the following output:
<NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
注解
请注意,在调试使用的程序时 XStreamingElement ,显示对象的值将导致 ToString 调用其方法。Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. 这将导致对 XML 进行序列化。This causes the XML to be serialized. 如果流式处理元素查询的语义使得流式处理元素只能流式传输一次,则这可能会导致在调试过程中出现意外的行为。If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.
适用于
ToString(SaveOptions)
返回此流元素的 XML,还可以选择禁用格式设置。Returns the XML for this streaming element, 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
指定格式设置行为的 SaveOptions。A SaveOptions that specifies formatting behavior.
返回
包含 XML 的 String。A String containing the XML.
示例
下面的示例演示了的两种用法 ToString 。The following example shows two uses of ToString. 第一次使用将保留空白。The first use preserves white space. 第二个序列化, XStreamingElement 并将设置为格式。The second one serializes the XStreamingElement with formatting.
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())
该示例产生下面的输出:This example produces the following output:
<NewRoot><DifferentChild>3</DifferentChild></NewRoot>
------
<NewRoot>
<DifferentChild>3</DifferentChild>
</NewRoot>
注解
请注意,在调试使用的程序时 XStreamingElement ,显示对象的值将导致 ToString 调用其方法。Note that when debugging a program that uses XStreamingElement, displaying the value of an object causes its ToString method to be called. 这将导致对 XML 进行序列化。This causes the XML to be serialized. 如果流式处理元素查询的语义使得流式处理元素只能流式传输一次,则这可能会导致在调试过程中出现意外的行为。If the semantics of your streaming element query are such that the streaming element can only be streamed once, this may cause undesirable behavior in your debugging experience.