---
title: "init(contentsOf:options:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/xmldocument/init(contentsof:options:)"
---

# init(contentsOf:options:)

Initializes and returns an NSXMLDocument object created from the XML or HTML contents of a URL-referenced source

## Declaration

```swift
convenience init(contentsOf url: URL, options mask: XMLNode.Options = []) throws
```

## Parameters

- `url`: An doc://com.apple.foundation/documentation/Foundation/NSURL object specifying a URL source.
- `mask`: A bit mask for input options. You can specify multiple options by bit-OR’ing them. See Constants for a list of valid input options.

## Return Value

Return Value An initialized NSXMLDocument object, or  nil if initialization fails because of parsing errors or other reasons.

## Discussion

Discussion note: In Swift, this method returns a nonoptional result 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

### Related Documentation

- [Tree-Based XML Programming Guide](apple-archive/documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html.md)

### Initializing NSXMLDocument Objects

- [init(data:options:)](foundation/xmldocument/init(data:options:).md)
- [init(rootElement:)](foundation/xmldocument/init(rootelement:).md)
- [init(xmlString:options:)](foundation/xmldocument/init(xmlstring:options:)-65m2r.md)
- [replacementClass(for:)](foundation/xmldocument/replacementclass(for:).md)
