NSXMLParser (SAX parsing) Large File Parsing

Source: Internet
Author: User

NSXMLParser (SAX parsing) Large File Parsing
NSXMLParser (SAX parsing) Large File Parsing

-(Void) viewDidLoad
{
[

{
[SuperviewDidLoad];
// 1. Create a URL
NSURL * url = HMUrl (@ "video? Type = XML ");

// 2. Create a request
NSURLRequest * request = [NSURLRequestrequestWithURL: url];

// 3. Send the request
[NSURLConnectionsendAsynchronousRequest: requestqueue: [NSOperationQueuemainQueue] completionHandler: ^ (NSURLResponse * response, NSData * data, NSError * connectionError ){
If (connectionError | data = nil ){
[MBProgressHUDshowError: @ "the network is busy. Please try again later! "];
Return;
}

// Parse XML data

// 1. Create an XML Parser -- SAX -- parse elements one by one
NSXMLParser * parser = [[NSXMLParseralloc] initWithData: data];

// 2. Set proxy
Parser. delegate = self;

// 3. Start parsing (synchronous execution)
[Parser parse];

// 4. Refresh the table
[Self. tableViewreloadData];
}];
}

# Proxy method of pragma mark-NSXMLParser
/**
* It is called when it is parsed to the beginning of the document.
*/
-(Void) parserDidStartDocument :( NSXMLParser *) parser
{
// NSLog (@ "parserDidStartDocument ----");
}

/**
* It is called when an element is parsed to the beginning.
*
* @ Param elementName: element name
* @ Param attributeDict attribute dictionary
*/
-(Void) parser :( NSXMLParser *) parser didStartElement :( NSString *) elementName namespaceURI :( NSString *) namespaceURI qualifiedName :( NSString *) qName attributes :( NSDictionary *) attributeDict
{
If ([@ "videos" isEqualToString: elementName]) return;

HMVideo * video = [HMVideovideoWithDict: attributeDict];
[Self. videosaddObject: video];
}

/**
* After an element is parsed, it is called.
*
* @ Param elementName: element name
*/
-(Void) parser :( NSXMLParser *) parser didEndElement :( NSString *) elementName namespaceURI :( NSString *) namespaceURI qualifiedName :( NSString *) qName
{
// NSLog (@ "didEndElement ---- % @", elementName );
}

/**
* It will be called when it is parsed to the end of the document (resolution ends)
*/
-(Void) parserDidEndDocument :( NSXMLParser *) parser
{
// NSLog (@ "parserDidEndDocument ----");
}

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.