---
title: "element(withName:children:attributes:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/xmlnode/element(withname:children:attributes:)"
---

# element(withName:children:attributes:)

Returns an XMLElement object with the given tag (name), attributes, and children.

## Declaration

```swift
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 doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/element, doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/processingInstruction, doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/comment, and doc://com.apple.foundation/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 doc://com.apple.foundation/documentation/Foundation/XMLNode/Kind-swift.enum/attribute. Specify nil if there are no attributes to add to this node object.

## Return Value

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

## See Also

### Creating and Initializing Node Objects

- [init(kind:)](foundation/xmlnode/init(kind:).md)
- [init(kind:options:)](foundation/xmlnode/init(kind:options:).md)
- [document()](foundation/xmlnode/document().md)
- [document(withRootElement:)](foundation/xmlnode/document(withrootelement:).md)
- [element(withName:)](foundation/xmlnode/element(withname:).md)
- [element(withName:stringValue:)](foundation/xmlnode/element(withname:stringvalue:).md)
- [element(withName:uri:)](foundation/xmlnode/element(withname:uri:).md)
- [attribute(withName:stringValue:)](foundation/xmlnode/attribute(withname:stringvalue:).md)
- [attribute(withName:uri:stringValue:)](foundation/xmlnode/attribute(withname:uri:stringvalue:).md)
- [text(withStringValue:)](foundation/xmlnode/text(withstringvalue:).md)
- [comment(withStringValue:)](foundation/xmlnode/comment(withstringvalue:).md)
- [namespace(withName:stringValue:)](foundation/xmlnode/namespace(withname:stringvalue:).md)
- [dtdNode(withXMLString:)](foundation/xmlnode/dtdnode(withxmlstring:).md)
- [predefinedNamespace(forPrefix:)](foundation/xmlnode/predefinednamespace(forprefix:).md)
- [processingInstruction(withName:stringValue:)](foundation/xmlnode/processinginstruction(withname:stringvalue:).md)
