XText.Value Property (System.Xml.Linq)

Switch View :
ScriptFree
.NET Framework Class Library
XText.Value Property

Gets or sets the value of this node.

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

Visual Basic
Public Property Value As String
	Get
	Set
C#
public string Value { get; set; }
Visual C++
public:
property String^ Value {
	String^ get ();
	void set (String^ value);
}
F#
member Value : string with get, set

Property Value

Type: System.String
A String that contains the value of this node.
Remarks

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

Examples

The following example shows getting and setting this property.

C#
XElement root = new XElement("Root", "Some text");
XText txtNode = root.Nodes().OfType<XText>().First();
Console.WriteLine(txtNode.Value);
txtNode.Value = "New text";
Console.WriteLine(txtNode.Value);

root.Value = "Newer text";
txtNode = root.Nodes().OfType<XText>().First();
Console.WriteLine(txtNode.Value);
Visual Basic
Dim root As XElement = <Root>Some text</Root>
Dim txtNode As XText = root.Nodes().OfType(Of XText).First()
Console.WriteLine(txtNode.Value)
txtNode.Value = "New text"
Console.WriteLine(txtNode.Value)

root.Value = "Newer text"
txtNode = root.Nodes().OfType(Of XText).First()
Console.WriteLine(txtNode.Value)

This example produces the following output:

Some text
New text
Newer text
Version Information

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Other Resources