---
title: "attribute(forName:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/xmlelement/attribute(forname:)"
---

# attribute(forName:)

Returns the attribute node of the receiver with the specified name.

## Declaration

```swift
func attribute(forName name: String) -> XMLNode?
```

## Parameters

- `name`: A string specifying the name of an attribute.

## Return Value

Return Value An XML node object representing a matching attribute or nil if no such node was found.

## Discussion

Discussion If name is a qualified name, then this method invokes attribute(forLocalName:uri:) with the URI parameter set to the URI associated with the prefix. Otherwise comparison is based on string equality of the qualified or non-qualified name.

## See Also

### Handling Attributes

- [addAttribute(_:)](foundation/xmlelement/addattribute(_:).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)
