语言

XAttribute.ToString 方法

定义

将当前 XAttribute 对象转换为字符串表示形式。

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

返回

String包含特性及其值的 XML 文本表示形式。

示例

以下示例创建一个具有多个属性的元素。 然后,它通过调用此方法获取属性并显示它及其内容。

XElement root = new XElement("Root",
    new XAttribute("Att1", "content1"),
    new XAttribute("Att2", "content2"),
    new XAttribute("Att3", "content3")
);
XAttribute att = root.Attribute("Att2");
Console.WriteLine(att.ToString());
Dim root As XElement = <Root Att1="content1" Att2="content2" Att3="content3"/>
Dim att As XAttribute = root.Attribute("Att2")
Console.WriteLine(att.ToString())

此示例生成以下输出:

Att2="content2"

注解

此方法以 . AttributeName="content"的形式返回一个字符串。

Warning

调用此方法并 XAttribute 包含控制字符时,将引发异常,其消息如下:十六进制值0x0B是无效字符。

适用于

另请参阅