XNode.ToString Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns the XML for this node, optionally disabling formatting.
Overloads
ToString() |
Returns the indented XML for this node. |
ToString(SaveOptions) |
Returns the XML for this node, optionally disabling formatting. |
ToString()
- Source:
- XNode.cs
- Source:
- XNode.cs
- Source:
- XNode.cs
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
Returns
A String containing the indented XML.
Examples
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>
See also
Applies to
ToString(SaveOptions)
- Source:
- XNode.cs
- Source:
- XNode.cs
- Source:
- XNode.cs
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
Parameters
- options
- SaveOptions
A SaveOptions that specifies formatting behavior.
Returns
A String containing the XML.
Examples
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>
See also
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기