Share via


XAttribute.ToString Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the current XAttribute object to a string representation.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

Syntax

'Declaration
Public Overrides Function ToString As String
public override string ToString()

Return Value

Type: System.String
A String containing the XML text representation of an attribute and its value.

Remarks

This method returns a string in the form of AttributeName="content".

Examples

The following example creates an element with several attributes. It then gets an attribute and displays it and its content by calling this method.

Dim output As New StringBuilder
Dim root As XElement = <Root Att1="content1" Att2="content2" Att3="content3"/>
Dim att As XAttribute = root.Attribute("Att2")
output.Append(att.ToString())
output.Append(Environment.NewLine)

OutputTextBlock.Text = output.ToString()
StringBuilder output = new StringBuilder();
XElement root = new XElement("Root",
    new XAttribute("Att1", "content1"),
    new XAttribute("Att2", "content2"),
    new XAttribute("Att3", "content3")
);
XAttribute att = root.Attribute("Att2");
output.Append(att.ToString());
output.Append(Environment.NewLine);

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.