XmlElement.SetAttributeNode Method (XmlAttribute)


Adds the specified XmlAttribute.

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

public virtual XmlAttribute SetAttributeNode(
	XmlAttribute newAttr


Type: System.Xml.XmlAttribute

The XmlAttribute node to add to the attribute collection for this element.

Return Value

Type: System.Xml.XmlAttribute

If the attribute replaces an existing attribute with the same name, the old XmlAttribute is returned; otherwise, null is returned.

Exception Condition

The newAttr was created from a different document than the one that created this node. Or this node is read-only.


The newAttr is already an attribute of another XmlElement object. You must explicitly clone XmlAttribute nodes to re-use them in other XmlElement objects.

If an attribute with that name is already present in the element, it is replaced by the new one.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top