<!--
{
  "availability" : [
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/XMLDTD",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXMLDTD"
  },
  "title" : "XMLDTD"
}
-->

# XMLDTD

A representation of a Document Type Definition.

```
class XMLDTD
```

## Overview

An instance of the [`XMLDTD`](/documentation/Foundation/XMLDTD) class is held as a property of an [`XMLDocument`](/documentation/Foundation/XMLDocument) instance, accessed through the [`XMLDocument`](/documentation/Foundation/XMLDocument) property [`dtd`](/documentation/Foundation/XMLDocument/dtd).

In the data model, an [`XMLDTD`](/documentation/Foundation/XMLDTD) object is conceptually similar to namespace and attribute nodes: it is not considered to be a child of the [`XMLDocument`](/documentation/Foundation/XMLDocument) object although it is closely associated with it. It is at the “root” of a shallow tree consisting primarily of nodes representing DTD declarations. Acceptable child nodes are instances of the [`XMLDTDNode`](/documentation/Foundation/XMLDTDNode) class as well as [`XMLNode`](/documentation/Foundation/XMLNode) objects representing comment nodes and processing-instruction nodes.

You create an `NSXMLDTD` object in one of three ways:

- By processing an XML document with its own internal (in-line) DTD
- By process a standalone (external) DTD
- Programmatically

Once an [`XMLDTD`](/documentation/Foundation/XMLDTD) instance is in place, you can add, remove, and change the [`XMLDTDNode`](/documentation/Foundation/XMLDTDNode) objects representing various DTD declarations. When you write the document out as XML, the new or modified internal DTD is included (assuming you set the DTD in the [`XMLDocument`](/documentation/Foundation/XMLDocument) instance). You may also programmatically create an external DTD and write that out to its own file.

## Topics

### Initializing an NSXMLDTD Object

[`-  initWithContentsOfURL:options:error:`](/documentation/Foundation/XMLDTD/init(contentsOf:options:))

Initializes and returns an `NSXMLDTD` object created from the DTD declarations in a URL-referenced source.

[`-  initWithData:options:error:`](/documentation/Foundation/XMLDTD/init(data:options:))

Initializes and returns an `NSXMLDTD` object created from the DTD declarations encapsulated in an [`NSData`](/documentation/Foundation/NSData) object

### Managing DTD Identifiers

[`publicID`](/documentation/Foundation/XMLDTD/publicID)

Returns the receiver’s public identifier.

[`systemID`](/documentation/Foundation/XMLDTD/systemID)

Returns the receiver’s system identifier.

### Manipulating Child Nodes

[`-  addChild:`](/documentation/Foundation/XMLDTD/addChild(_:))

Adds a child node to the end of the list of existing children.

[`-  insertChild:atIndex:`](/documentation/Foundation/XMLDTD/insertChild(_:at:))

Inserts a child node in the receiver’s list of children at a specific location in the list.

[`-  insertChildren:atIndex:`](/documentation/Foundation/XMLDTD/insertChildren(_:at:))

Inserts an array of child nodes at a specified location in the receiver’s list of children.

[`-  removeChildAtIndex:`](/documentation/Foundation/XMLDTD/removeChild(at:))

Removes the child node at a particular location in the receiver’s list of children.

[`-  replaceChildAtIndex:withNode:`](/documentation/Foundation/XMLDTD/replaceChild(at:with:))

Replaces a child at a particular index with another child.

[`-  setChildren:`](/documentation/Foundation/XMLDTD/setChildren(_:))

Removes all existing children of the receiver and replaces them with an array of new child nodes.

### Getting DTD Nodes by Name

[`+  predefinedEntityDeclarationForName:`](/documentation/Foundation/XMLDTD/predefinedEntityDeclaration(forName:))

Returns a DTD node representing the predefined entity declaration with the specified name.

[`-  elementDeclarationForName:`](/documentation/Foundation/XMLDTD/elementDeclaration(forName:))

Returns the DTD node representing an element declaration for a specified element.

[`-  attributeDeclarationForName:elementName:`](/documentation/Foundation/XMLDTD/attributeDeclaration(forName:elementName:))

Returns the DTD node representing an attribute-list declaration for a given attribute and its element.

[`-  entityDeclarationForName:`](/documentation/Foundation/XMLDTD/entityDeclaration(forName:))

Returns the DTD node representing the entity declaration for a specified entity.

[`-  notationDeclarationForName:`](/documentation/Foundation/XMLDTD/notationDeclaration(forName:))

Returns the DTD node representing the notation declaration identified by the specified notation name.

## Relationships

### Conforms To

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CVarArg`](/documentation/Swift/CVarArg)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`XMLNode`](/documentation/Foundation/XMLNode)

---

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)