CopyPastehas never been so tasty!

lesson 8 codes

by anonymous

  • 0
  • 0
  • 0
130 views

//=================== Parser Methods ===========================//

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if ([elementName isEqualToString:@"CD"])
         {
             CD* newClip = [[CD alloc] init];
             currCD = newClip;
         }
}
// sent when the parser finds an element start tag.
// In the case of the cvslog tag, the following is what the delegate receives:
//   elementName == cvslog, namespaceURI == http://xml.apple.com/cvslog, qualifiedName == cvslog
// In the case of the radar tag, the following is what's passed in:
//    elementName == radar, namespaceURI == http://xml.apple.com/radar, qualifiedName == radar:radar
// If namespace processing >isn't< on, the xmlns:radar="http://xml.apple.com/radar" is returned as an attribute pair, the elementName is 'radar:radar' and there is no qualifiedName.


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if (!currString)
    {
        currString = [[NSMutableString alloc] init];
    }
   
    [currString appendString:string];
   
}
// This returns the string of the characters encountered thus far. You may not necessarily get the longest character run. The parser reserves the right to hand these to the delegate as potentially many calls in a row to -parser:foundCharacters:

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    if ([elementName isEqualToString:@"CATALOG"])
    {
        return;
    }
   
    if ([elementName isEqualToString:@"CD"])
    {
        [myJukeBox addClip:currCD];
   
        static int i = 1;
        NSLog(@"------------------------------");
        NSArray* tmpArr = [NSArray arrayWithArray:[myJukeBox getCDs]];
        NSLog(@"there are %d elements in the array",[tmpArr count]);
        for (CD* elem in tmpArr)
            NSLog(@"%d@,%@,%@,%@,%@,%@",i,elem.TTITLE,elem.ARTIST,elem.COUNTRY,elem.PRICE,elem.YEAR);
        i++
        return;
    }
   
}
// sent when an end tag is encountered. The various parameters are supplied as above.

Add A Comment: