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:
property String^ Value {
	String^ get();
	void set(String^ value);
}

Property Value

Type: System::String^

A String containing the value of this attribute.

Exception Condition
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.

No code example is currently available or this language may not be supported.

This example produces the following output:


                content
new text

The following example shows the benefit of using the explicit conversion operators to get the value of an attribute that might not exist:

No code example is currently available or this language may not be supported.

This example produces the following output:


                c1:attribute 1 content
c2:2
c3:attribute does not exist
c4:attribute does not exist

v1:attribute 1 content
v2:2
v3:attribute does not exist
v4:attribute does not exist

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: