Compartir a través de


XAttribute Constructor (XAttribute)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Sub New ( _
    other As XAttribute _
)
public XAttribute(
    XAttribute other
)

Parameters

Exceptions

Exception Condition
ArgumentNullException

The other parameter is nulla null reference (Nothing in Visual Basic).

Remarks

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

Examples

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

Dim output As New StringBuilder
Dim root1 As XElement = <Root Att1='abc'/>
' Make a deep copy.
Dim root2 As XElement = New XElement(root1)
If root1.Attribute("Att1") Is root2.Attribute("Att1") Then
    output.Append("This will not be printed")
    output.Append(Environment.NewLine)
Else
    output.Append("Creating a deep copy created a new attribute from the original.")
    output.Append(Environment.NewLine)
End If

OutputTextBlock.Text = output.ToString()
StringBuilder output = new StringBuilder();
XElement root1 = XElement.Parse("<Root Att1='abc' />");
// Make a deep copy.
XElement root2 = new XElement(root1);
if (root1.Attribute("Att1") == root2.Attribute("Att1"))
    output.Append("This will not be printed" + Environment.NewLine);
else
    output.Append("Creating a deep copy created a new attribute from the original." + Environment.NewLine);

OutputTextBlock.Text = output.ToString();

Version Information

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

Platforms

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