---
title: "init(xmlString:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/xmlelement/init(xmlstring:)-7vkg7"
---

# init(xmlString:)

Returns an NSXMLElement object created from a specified string containing XML markup.

## Declaration

```swift
init(xmlString string: String) throws
```

## Parameters

- `string`: A string containing XML markup for an element.

## Return Value

Return Value The initialized NSXMLElement object or nil if initialization did not succeed.

## Discussion

Discussion note: In Swift, this API is imported as an initializer and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Initializing NSXMLElement Objects

- [init(name:)](foundation/xmlelement/init(name:).md)
- [init(name:stringValue:)](foundation/xmlelement/init(name:stringvalue:).md)
- [init(name:uri:)](foundation/xmlelement/init(name:uri:)-1r286.md)
- [init(kind:options:)](foundation/xmlelement/init(kind:options:).md)
