Modifying Elements, Attributes, and Nodes in an XML Tree

The following table summarizes the methods and properties that you can use to modify an element, its child elements, or its attributes.

The following methods modify an XElement.

Method Description

System.Xml.Linq.XElement.Parse

Replaces an element with parsed XML.

System.Xml.Linq.XElement.RemoveAll

Removes all content (child nodes and attributes) of an element.

System.Xml.Linq.XElement.RemoveAttributes

Removes the attributes of an element.

System.Xml.Linq.XElement.ReplaceAll

Replaces all content (child nodes and attributes) of an element.

System.Xml.Linq.XElement.ReplaceAttributes

Replaces the attributes of an element.

System.Xml.Linq.XElement.SetAttributeValue(System.Xml.Linq.XName,System.Object)

Sets the value of an attribute. Creates the attribute if it doesn't exist. If the value is set to null, removes the attribute.

System.Xml.Linq.XElement.SetElementValue(System.Xml.Linq.XName,System.Object)

Sets the value of a child element. Creates the element if it doesn't exist. If the value is set to null, removes the element.

System.Xml.Linq.XElement.Value

Replaces the content (child nodes) of an element with the specified text.

System.Xml.Linq.XElement.SetValue(System.Object)

Sets the value of an element.

The following methods modify an XAttribute.

Method Description

System.Xml.Linq.XAttribute.Value

Sets the value of an attribute.

System.Xml.Linq.XAttribute.SetValue(System.Object)

Sets the value of an attribute.

The following methods modify an XNode (including an XElement or XDocument).

Method Description

System.Xml.Linq.XNode.ReplaceWith

Replaces a node with new content.

The following methods modify an XContainer (an XElement or XDocument).

Method Description

System.Xml.Linq.XContainer.ReplaceNodes

Replaces the children nodes with new content.

See Also

Other Resources

Modifying XML Trees (LINQ to XML)

Build Date:

2012-08-02