XElement Constructor (XElement)
Collapse the table of content
Expand the table of content

XElement Constructor (XElement)

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

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

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

public XElement(
	XElement other
)

Parameters

other
Type: System.Xml.Linq.XElement
An XElement object to copy from.

This constructor makes a deep copy of an element.

The following example creates an XML tree, creates a clone of the tree, and then calls DeepEquals, which tests whether the two XML trees are equal.


StringBuilder output = new StringBuilder();
XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", 1),
    new XElement("Child1", 1),
    new XElement("Child2", 2)
);

// Create a clone of the tree.
XElement treeClone = new XElement(xmlTree);

output.Append("xmlTree = treeClone: " + XNode.DeepEquals(xmlTree, treeClone) + Environment.NewLine);

// Do some work with xmlTree, perhaps pass it to other methods.
xmlTree.Add(new XElement("Child3", 3));

output.Append("xmlTree = treeClone: " + XNode.DeepEquals(xmlTree, treeClone) + Environment.NewLine);

OutputTextBlock.Text = output.ToString();


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft