---
title: XMLParser
framework: foundation
role: symbol
role_heading: Class
path: foundation/xmlparser
---

# XMLParser

An event driven parser of XML documents (including DTD declarations).

## Declaration

```swift
class XMLParser
```

## Overview

Overview An XMLParser notifies its delegate about the items (elements, attributes, CDATA blocks, comments, and so on) that it encounters as it processes an XML document. It does not itself do anything with those parsed items except report them. It also reports parsing errors. For convenience, an XMLParser object in the following descriptions is sometimes referred to as a parser object. Unless used in a callback, the XMLParser is a thread-safe class as long as any given instance is only used in one thread. note: Namespace support was implemented in XMLParser starting in macOS 10.4. Namespace-related methods of XMLParser prior to this version have no effect.

## Topics

### Initializing a Parser Object

- [init(contentsOf:)](foundation/xmlparser/init(contentsof:).md)
- [init(data:)](foundation/xmlparser/init(data:).md)
- [init(stream:)](foundation/xmlparser/init(stream:).md)

### Managing Delegates

- [delegate](foundation/xmlparser/delegate.md)

### Managing Parser Behavior

- [shouldProcessNamespaces](foundation/xmlparser/shouldprocessnamespaces.md)
- [shouldReportNamespacePrefixes](foundation/xmlparser/shouldreportnamespaceprefixes.md)
- [shouldResolveExternalEntities](foundation/xmlparser/shouldresolveexternalentities.md)

### Parsing

- [parse()](foundation/xmlparser/parse().md)
- [abortParsing()](foundation/xmlparser/abortparsing().md)
- [parserError](foundation/xmlparser/parsererror.md)

### Obtaining Parser State

- [columnNumber](foundation/xmlparser/columnnumber.md)
- [lineNumber](foundation/xmlparser/linenumber.md)
- [publicID](foundation/xmlparser/publicid.md)
- [systemID](foundation/xmlparser/systemid.md)

### Constants

- [XMLParser.ExternalEntityResolvingPolicy](foundation/xmlparser/externalentityresolvingpolicy-swift.enum.md)
- [errorDomain](foundation/xmlparser/errordomain.md)
- [XMLParser.ErrorCode](foundation/xmlparser/errorcode.md)

### Initializers

- [init(contentsOfURL:)](foundation/xmlparser/init(contentsofurl:).md)

### Instance Properties

- [allowedExternalEntityURLs](foundation/xmlparser/allowedexternalentityurls.md)
- [externalEntityResolvingPolicy](foundation/xmlparser/externalentityresolvingpolicy-swift.property.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Event-Based Processing

- [XMLParserDelegate](foundation/xmlparserdelegate.md)
