[IOS] parses XML using nsxmlparser

Source: Internet
Author: User

1. Start nsxmlparser

To use nsxmlparser, you must first create it and set various attributes. The following methods are used:

Initwithcontentsofurl creates a parser through nsurl

InitwithdataCreate a parser through nsdata, for example, xmlpaser = [[nsxmlparse alloc] initwithdata: webdata];

SetdelegateDefine a delegate for the parser

ParseRun the parser

2. Act as delegate

The five most important methods:

//Element start character foundProcessing functions
(That is, the beginning of the report element and the attributes of the element)

Method 1.-(Void) parser :( nsxmlparser *) parser

        Didstartelement:( Nsstring *) elementname

Namespaceuri :( nsstring *) namespaceuri

Qualifiedname :( nsstring *) QNAME

Attributes :( nsdictionary *) attributedict

Method 2 .//Processing tag contains content characters
(All or part of the report element)

-(Void) parser :( nsxmlparser *)Parser foundcharacters:( Nsstring *) String

Method 3. // discover elementsHandler Of The TerminatorTo save the data of each element Project (that is, the end mark of the report element)

-(Void) parser :( nsxmlparser *) parser

        Didendelement:( Nsstring *) elementname

Namespaceuri :( nsstring *) namespaceuri

Qualifiedname :( nsstring *) QNAME

Method 4. // reportResolution end

-(Void)Parserdidenddocument:( Nsxmlparser *) parser

Method 5. // report unrecoverable parsing errors

-(Void) paser: parsererroccured

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.