XAttribute.Value Property

Gets or sets the value of this attribute.

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

public string Value { get; set; }

Property Value

Type: System.String
A String containing the value of this attribute.

ExceptionCondition
ArgumentNullException

When setting, the value is null.

You can use this property to get or set the value of an attribute.

Setting this property will raise the Changed and the Changing events.

If you are getting the value and the attribute might not exist, it is more convenient to use the explicit conversion operators, and assign the attribute to a nullable type such as string or Nullable<T> of Int32. If the attribute does not exist, then the nullable type is set to null. Before using this property, you must make sure that the Attribute method does not return null.

The following example creates an element with an attribute. It then retrieves the value of the attribute, and then sets it.

Note that the Visual Basic example uses the XML attribute property.


StringBuilder output = new StringBuilder();
XElement root = new XElement("Root",
    new XAttribute("Att", "content")
);
XAttribute att = root.FirstAttribute;
output.Append(att.Value + Environment.NewLine);
att.Value = "new text";
output.Append(att.Value + Environment.NewLine);

OutputTextBlock.Text = output.ToString();


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

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

Community Additions

ADD
Show: