iOS Developer Library

Developer

Foundation Framework Reference NSXMLParserDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSXMLParserDelegate

Inherits From


Not Applicable

Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 4.0 and later

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

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

    Declaration

    Swift

    optional func parserDidStartDocument(_ parser: NSXMLParser)

    Objective-C

    - (void)parserDidStartDocument:(NSXMLParser *)parser

    Parameters

    parser

    A parser object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parserDidEndDocument(_ parser: NSXMLParser)

    Objective-C

    - (void)parserDidEndDocument:(NSXMLParser *)parser

    Parameters

    parser

    A parser object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, didStartElement elementName: String, namespaceURI namespaceURI: String?, qualifiedName qualifiedName: String?, attributes attributeDict: [NSObject : AnyObject])

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, didEndElement elementName: String, namespaceURI namespaceURI: String?, qualifiedName qName: String?)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, didStartMappingPrefix prefix: String, toURI namespaceURI: String)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, didEndMappingPrefix prefix: String)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, resolveExternalEntityName entityName: String, systemID systemID: String?) -> NSData?

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, parseErrorOccurred parseError: NSError)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

  • 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.

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, validationErrorOccurred validError: NSError)

    Objective-C

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

    Parameters

    parser

    A parser object.

    validError

    An NSError object describing the validation error that occurred.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, foundCharacters string: String?)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

  • 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.

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, foundIgnorableWhitespace whitespaceString: String)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, foundProcessingInstructionWithTarget target: String, data data: String?)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, foundComment comment: String?)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0

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

    Declaration

    Swift

    optional func parser(_ parser: NSXMLParser, foundCDATA CDATABlock: NSData)

    Objective-C

    - (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:.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 2.0 and later

    Available as part of an informal protocol prior to iOS 4.0