NSXMLParserDelegate Protocol Reference

Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in iOS 4.0 and later.
Companion guide
Declared in
NSXMLParser.h
Related sample code

Overview

The NSXMLParserDelegate protocol defines the optional methods implemented by delegates of NSXMLParser objects.

Tasks

Handling XML

Handling the DTD

Instance Methods

parser:didEndElement:namespaceURI:qualifiedName:

Sent by a parser object to its delegate when it encounters an end tag for a specific element.

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
Parameters
parser

A parser object.

elementName

A string that is the name of an element (in its end tag).

namespaceURI

If namespace processing is turned on, contains the URI for the current namespace as a string object.

qName

If namespace processing is turned on, contains the qualified name for the current namespace as a string object.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:didEndMappingPrefix:

Sent by a parser object to its delegate when a given namespace prefix goes out of scope.

- (void)parser:(NSXMLParser *)parser didEndMappingPrefix:(NSString *)prefix
Parameters
parser

A parser object.

prefix

A string that is a namespace prefix.

Discussion

The parser sends this message only when namespace-prefix reporting is turned on through the setShouldReportNamespacePrefixes: method.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:didStartElement:namespaceURI:qualifiedName:attributes:

Sent by a parser object to its delegate when it encounters a start tag for a given element.

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
Parameters
parser

A parser object.

elementName

A string that is the name of an element (in its start tag).

namespaceURI

If namespace processing is turned on, contains the URI for the current namespace as a string object.

qualifiedName

If namespace processing is turned on, contains the qualified name for the current namespace as a string object.

attributeDict

A dictionary that contains any attributes associated with the element. Keys are the names of attributes, and values are attribute values.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:didStartMappingPrefix:toURI:

Sent by a parser object to its delegate the first time it encounters a given namespace prefix, which is mapped to a URI.

- (void)parser:(NSXMLParser *)parser didStartMappingPrefix:(NSString *)prefix toURI:(NSString *)namespaceURI
Parameters
parser

A parser object.

prefix

A string that is a namespace prefix.

namespaceURI

A string that specifies a namespace URI.

Discussion

The parser object sends this message only when namespace-prefix reporting is turned on through the setShouldReportNamespacePrefixes: method.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundAttributeDeclarationWithName:forElement:type:defaultValue:

Sent by a parser object to its delegate when it encounters a declaration of an attribute that is associated with a specific element.

- (void)parser:(NSXMLParser *)parser foundAttributeDeclarationWithName:(NSString *)attributeName forElement:(NSString *)elementName type:(NSString *)type defaultValue:(NSString *)defaultValue
Parameters
parser

An NSXMLParser object parsing XML.

attributeName

A string that is the name of an attribute.

elementName

A string that is the name of an element that has the attribute attributeName.

type

A string, such as "ENTITY", "NOTATION", or "ID", that indicates the type of the attribute.

defaultValue

A string that specifies the default value of the attribute.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundCDATA:

Sent by a parser object to its delegate when it encounters a CDATA block.

- (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock
Parameters
parser

An NSXMLParser object parsing XML.

CDATABlock

A data object containing a block of CDATA.

Discussion

Through this method the parser object passes the contents of the block to its delegate in an NSData object. The CDATA block is character data that is ignored by the parser. The encoding of the character data is UTF-8. To convert the data object to a string object, use the NSString method initWithData:encoding:.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundCharacters:

Sent by a parser object to provide its delegate with a string representing all or part of the characters of the current element.

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
Parameters
parser

A parser object.

string

A string representing the complete or partial textual content of the current element.

Discussion

The parser object may send the delegate several parser:foundCharacters: messages to report the characters of an element. Because string may be only part of the total character content for the current element, you should append it to the current accumulation of characters until the element changes.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundComment:

Sent by a parser object to its delegate when it encounters a comment in the XML.

- (void)parser:(NSXMLParser *)parser foundComment:(NSString *)comment
Parameters
parser

An NSXMLParser object parsing XML.

comment

A string that is a the content of a comment in the XML.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundElementDeclarationWithName:model:

Sent by a parser object to its delegate when it encounters a declaration of an element with a given model.

- (void)parser:(NSXMLParser *)parser foundElementDeclarationWithName:(NSString *)elementName model:(NSString *)model
Parameters
parser

An NSXMLParser object parsing XML.

elementName

A string that is the name of an element.

model

A string that specifies a model for elementName.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundExternalEntityDeclarationWithName:publicID:systemID:

Sent by a parser object to its delegate when it encounters an external entity declaration.

- (void)parser:(NSXMLParser *)parser foundExternalEntityDeclarationWithName:(NSString *)entityName publicID:(NSString *)publicID systemID:(NSString *)systemID
Parameters
parser

An NSXMLParser object parsing XML.

entityName

A string that is the name of an entity.

publicID

A string that specifies the public ID associated with entityName.

systemID

A string that specifies the system ID associated with entityName.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundIgnorableWhitespace:

Reported by a parser object to provide its delegate with a string representing all or part of the ignorable whitespace characters of the current element.

- (void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespaceString
Parameters
parser

A parser object.

whitespaceString

A string representing all or part of the ignorable whitespace characters of the current element.

Discussion

All the whitespace characters of the element (including carriage returns, tabs, and new-line characters) may not be provided through an individual invocation of this method. The parser may send the delegate several parser:foundIgnorableWhitespace: messages to report the whitespace characters of an element. You should append the characters in each invocation to the current accumulation of characters.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundInternalEntityDeclarationWithName:value:

Sent by a parser object to the delegate when it encounters an internal entity declaration.

- (void)parser:(NSXMLParser *)parser foundInternalEntityDeclarationWithName:(NSString *)name value:(NSString *)value
Parameters
parser

An NSXMLParser object parsing XML.

name

A string that is the declared name of an internal entity.

value

A string that is the value of entity name.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundNotationDeclarationWithName:publicID:systemID:

Sent by a parser object to its delegate when it encounters a notation declaration.

- (void)parser:(NSXMLParser *)parser foundNotationDeclarationWithName:(NSString *)name publicID:(NSString *)publicID systemID:(NSString *)systemID
Parameters
parser

An NSXMLParser object parsing XML.

name

A string that is the name of the notation.

publicID

A string specifying the public ID associated with the notation name.

systemID

A string specifying the system ID associated with the notation name.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundProcessingInstructionWithTarget:data:

Sent by a parser object to its delegate when it encounters a processing instruction.

- (void)parser:(NSXMLParser *)parser foundProcessingInstructionWithTarget:(NSString *)target data:(NSString *)data
Parameters
parser

A parser object.

target

A string representing the target of a processing instruction.

data

A string representing the data for a processing instruction.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:foundUnparsedEntityDeclarationWithName:publicID:systemID:notationName:

Sent by a parser object to its delegate when it encounters an unparsed entity declaration.

- (void)parser:(NSXMLParser *)parser foundUnparsedEntityDeclarationWithName:(NSString *)name publicID:(NSString *)publicID systemID:(NSString *)systemID notationName:(NSString *)notationName
Parameters
parser

An NSXMLParser object parsing XML.

name

A string that is the name of the unparsed entity in the declaration.

publicID

A string specifying the public ID associated with the entity name.

systemID

A string specifying the system ID associated with the entity name.

notationName

A string specifying a notation of the declaration of entity name.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:parseErrorOccurred:

Sent by a parser object to its delegate when it encounters a fatal error.

- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
Parameters
parser

A parser object.

parseError

An NSError object describing the parsing error that occurred.

Discussion

When this method is invoked, parsing is stopped. For further information about the error, you can query parseError or you can send the parser a parserError message. You can also send the parser lineNumber and columnNumber messages to further isolate where the error occurred. Typically you implement this method to display information about the error to the user.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:resolveExternalEntityName:systemID:

Sent by a parser object to its delegate when it encounters a given external entity with a specific system ID.

- (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName:(NSString *)entityName systemID:(NSString *)systemID
Parameters
parser

A parser object.

entityName

A string that specifies the external name of an entity.

systemID

A string that specifies the system ID for the external entity.

Return Value

An NSData object that contains the resolution of the given external entity.

Discussion

The delegate can resolve the external entity (for example, locating and reading an externally declared DTD) and provide the result to the parser object as an NSData object.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parser:validationErrorOccurred:

Sent by a parser object to its delegate when it encounters a fatal validation error. NSXMLParser currently does not invoke this method and does not perform validation.

- (void)parser:(NSXMLParser *)parser validationErrorOccurred:(NSError *)validError
Parameters
parser

A parser object.

validError

An NSError object describing the validation error that occurred.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parserDidEndDocument:

Sent by the parser object to the delegate when it has successfully completed parsing.

- (void)parserDidEndDocument:(NSXMLParser *)parser
Parameters
parser

A parser object.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h

parserDidStartDocument:

Sent by the parser object to the delegate when it begins parsing a document.

- (void)parserDidStartDocument:(NSXMLParser *)parser
Parameters
parser

A parser object.

Availability
  • Available in iOS 2.0 and later.
  • Available as part of an informal protocol prior to iOS 4.0.
Declared In
NSXMLParser.h