<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLNode/element(withName:children:attributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLNode(cm)elementWithName:children:attributes:"
  },
  "title" : "element(withName:children:attributes:)"
}
-->

# element(withName:children:attributes:)

Returns an [`XMLElement`](/documentation/Foundation/XMLElement) object with the given tag (name), attributes, and children.

```
class func element(withName name: String, children: [XMLNode]?, attributes: [XMLNode]?) -> Any
```

## Parameters

`name`

A string that is the name (tag identifier) of the element.

`children`

An array of `NSXMLElement` objects or `NSXMLNode` objects of kinds [`XMLNode.Kind.element`](/documentation/Foundation/XMLNode/Kind-swift.enum/element), [`XMLNode.Kind.processingInstruction`](/documentation/Foundation/XMLNode/Kind-swift.enum/processingInstruction), [`XMLNode.Kind.comment`](/documentation/Foundation/XMLNode/Kind-swift.enum/comment), and [`XMLNode.Kind.text`](/documentation/Foundation/XMLNode/Kind-swift.enum/text). Specify `nil` if there are no children to add to this node object.

`attributes`

An array of `NSXMLNode` objects of kind [`XMLNode.Kind.attribute`](/documentation/Foundation/XMLNode/Kind-swift.enum/attribute). Specify `nil` if there are no attributes to add to this node object.

## Return Value

An `NSXMLElement` object or `nil` if the object couldn’t be created.

---

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)