IOS learning and ios learning routes

Source: Internet
Author: User

IOS learning and ios learning routes

Preparations:

New-> file-> other-> Empty. In Save As:, you can specify the name suffix As. xml.

Copy below

<Person> <student> <pid> 1001 </pid> <name> James </name> <sex> male </sex> <age> 12 </age> </ student> </person>

Complete code

/// ViewController. m // XML // Created by CC on 16/8/29. // Copyright©2016 CC. all rights reserved. // # import "ViewController. h "@ interface ViewController () <NSXMLParserDelegate> @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self analysis];}-(void) analysis {NSString * filename = [[NSBundle mainBundle] pathForResource: @ "File. xml "ofType: nil]; NSData * data = [[NSData alloc] initWithContentsOfFile: filename]; NSXMLParser * parset = [[NSXMLParser alloc] initWithData: data]; parset. delegate = self; [parset parse];} // triggered at the beginning of the document. Only one-(void) parserDidStartDocument :( NSXMLParser *) parser {NSLog (@ "parsetStart ");} // trigger when a document error occurs-(void) parser :( NSXMLParser *) parser parseerroccurred :( NSError *) parseError {if (parseError) {NSLog (@ "parseError: % @", parseError) ;}}// trigger upon occurrence of a string-(void) parser :( NSXMLParser *) parser foundCharacters :( NSString *) string {NSLog (@ "00000000 ----- % @", string);} // when a start tag is triggered-(void) parser :( NSXMLParser *) parser didStartElement :( NSString *) elementName namespaceURI :( NSString *) namespaceURI qualifiedName :( NSString *) qName attributes :( NSDictionary <NSString *, NSString *> *) attributeDict {NSLog (@ "arrributeDict --- % @", attributeDict);} // triggered when an end tag is encountered-(void) parser :( NSXMLParser *) parser didEndElement :( NSString *) elementName namespaceURI :( NSString *) namespaceURI qualifiedName :( NSString *) qName {NSLog (@ "didEndElement ----- % @", elementName );} // triggered when the document ends-(void) parserDidEndDocument :( NSXMLParser *) parser {NSLog (@ "DidEndDocument");}-(void) didreceivemorywarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end

 

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.