---
title: "addAttribute(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmlelement/addattribute(_:)"
---

# addAttribute(_:)

Adds an attribute node to the receiver.

## Declaration

```swift
func addAttribute(_ attribute: XMLNode)
```

## Parameters

- `attribute`: An XML node object representing an attribute. If the receiver already has an attribute with the same name, anAttribute replaces the old attribute.

## Discussion

Discussion The order of multiple attributes is preserved if the NSXMLPreserveAttributeOrder option is specified when the element is created.

## See Also

### Handling Attributes

- [attribute(forName:)](foundation/xmlelement/attribute(forname:).md)
- [attribute(forLocalName:uri:)](foundation/xmlelement/attribute(forlocalname:uri:).md)
- [attributes](foundation/xmlelement/attributes.md)
- [removeAttribute(forName:)](foundation/xmlelement/removeattribute(forname:).md)
- [setAttributesWith(_:)](foundation/xmlelement/setattributeswith(_:).md)
- [setAttributesAs(_:)](foundation/xmlelement/setattributesas(_:).md)
