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

# init(contentsOf:options:)

Initializes and returns an NSXMLDTD object created from the DTD declarations in 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 identifying a URL source.
- `mask`: A bit mask specifying input options; bit-OR multiple options. The current valid options are NSXMLNodePreserveWhitespace and NSXMLNodePreserveEntities; these constants are described in the “Constants” section of the doc://com.apple.foundation/documentation/Foundation/XMLNode reference.

## Return Value

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

## Discussion

Discussion You use this method to create a stand-alone DTD which you can thereafter query and use for validation. You can associate the DTD created through this message with a document by setting the dtd property on an XMLDocument object. 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

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

### Initializing an NSXMLDTD Object

- [init(data:options:)](foundation/xmldtd/init(data:options:).md)
