<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLElement/setAttributesWith(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLElement(im)setAttributesWithDictionary:"
  },
  "title" : "setAttributesWith(_:)"
}
-->

# setAttributesWith(_:)

Sets the attributes of the receiver based on the key-value pairs specified in the passed dictionary.

```
func setAttributesWith(_ attributes: [String : String])
```

## Parameters

`attributes`

A dictionary of key-value pairs where the attribute name is the key and the object value of the attribute is the dictionary value.

## Discussion

The method uses these names and object values to create [`XMLNode`](/documentation/Foundation/XMLNode) objects of kind [`XMLNode.Kind.attribute`](/documentation/Foundation/XMLNode/Kind-swift.enum/attribute). Existing attributes are removed.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)