<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLDTDNode/init(xmlString:)-1dyhd",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLDTDNode(im)initWithXMLString:"
  },
  "title" : "init(xmlString:)"
}
-->

# init(xmlString:)

Returns an `NSXMLDTDNode` object initialized with the DTD declaration in a given string.

```
init?(xmlString string: String)
```

## Parameters

`string`

The DTD declaration.

## Return Value

An `NSXMLDTDNode` object initialized with the DTD declaration in `string`. Returns `nil` if initialization did not succeed, as might occur if the passed-in declaration is malformed.

## Discussion

The node kind (NSXMLNode) assigned to the returned object—element, attribute, entity, or notation declaration— is based on the full XML string that is parsed. To assign a subkind, set the [`dtdKind`](/documentation/Foundation/XMLDTDNode/dtdKind-swift.property) property.

You may also use the [`dtdNode(withXMLString:)`](/documentation/Foundation/XMLNode/dtdNode(withXMLString:)) or [`init(kind:)`](/documentation/Foundation/XMLNode/init(kind:)) methods to create `NSXMLDTDNode` instances. However, you cannot use the latter method to create `NSXMLDTDNode` instances for attribute-list declarations.

## See Also

  [Tree-Based XML Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/NSXML_Concepts/NSXML.html#//apple_ref/doc/uid/TP40001269)



---

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)