Value Property
Collapse the table of content
Expand the table of content

XAttribute.Value Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the value of this attribute.

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

'Declaration
Public Property Value As String

Property Value

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

ExceptionCondition
ArgumentNullException

When setting, the value is Nothing.

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(Of T) of Int32. If the attribute does not exist, then the nullable type is set to Nothing. Before using this property, you must make sure that the Attribute method does not return Nothing.

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.


Dim output As New StringBuilder
Dim root As XElement = <Root Att="content"/>
output.Append(root.@Att)
output.Append(Environment.NewLine)
root.@Att = "new text"
output.Append(root.@Att)
output.Append(Environment.NewLine)


OutputTextBlock.Text = output.ToString()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft