tailieunhanh - Phát triển ứng dụng cho iPhone và iPad - part 33
Tham khảo tài liệu 'phát triển ứng dụng cho iphone và ipad - part 33', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | XML and the iPhone SDK 289 Called when the parser finishes parsing the document - void parserDidEndDocument NSXMLParser parser NSLog parserDidEndDocument The code is relatively straightforward. First for illustrative purposes you log the name of the method that you are executing. This will prove instructive when you look at the console log. Examining the order in which the parser calls the delegate methods will help you to better understand how the parser works. Additionally it is useful for debugging purposes should you encounter an error in your parsing logic. In the parserDidStartDocument method you also initialize the inItemElement flag to NO because you are not currently in an item element. In the parserDidEndDocument method you log that you have reached the end of the document. Next you implement the start and end element functions. Here is the parser didStartElement namespaceURI qualifiedName attributes method implementation 0 Called when the parser encounters a start element - void parser NSXMLParser parser didStartElement NSString elementName download on a namespaceURI NSString namespaceURI qualifiedName NSString qualifiedName attributes NSDictionary attributeDict NSLog didStartElement Check to see which element we have found if elementName isEqualToString item We are in an item element inItemElement YES If we are in an item and found a title if inItemElement elementName isEqualToString title Initialize the capturedCharacters instance variable capturedCharacters NSMutableString alloc initWithCapacity 100 This method receives the name of the element that has started as a parameter. You check the name of the element and set the inItemElement flag if you have started an item element. Next check to see if you have started a title element. You may be wondering why you are checking to see if you have started a title element when you already know that you have started an item 290 CHAPTER 10 WORKING WITH
đang nạp các trang xem trước