Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XAttribute Constructor (XAttribute)

Initializes a new instance of the XAttribute class from another XAttribute object.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)
public XAttribute(
	XAttribute other
)

Parameters

other
Type: System.Xml.Linq.XAttribute

An XAttribute object to copy from.

ExceptionCondition
ArgumentNullException

The other parameter is null.

This constructor is primarily used internally when making a deep copy of an XML tree.

This example demonstrates that creating a deep copy of an XML tree creates a copy, not a clone, of an attribute in the tree.

XElement root1 = XElement.Parse("<Root Att1='abc' />");
// Make a deep copy.
XElement root2 = new XElement(root1);
if (root1.Attribute("Att1") == root2.Attribute("Att1"))
    Console.WriteLine("This will not be printed");
else
    Console.WriteLine("Creating a deep copy created a new attribute from the original.");

This example produces the following output:

Creating a deep copy created a new attribute from the original.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft. All rights reserved.