English 中文(简体)
• 如何利用国家扫盲和扫盲中心网站公布数据
原标题:How to parse data from a website using NSXMLParser

I want to get the updates from a website based on the titles and links which is in xml format.

我尝试了以下法典,但没有奏效。 仅此,它就发出以下信息:

2011-11-03 14:45:05.987 tabbar[673:e903] * Terminating app due to uncaught exception NSInvalidArgumentException , reason: -[NSCFString isEqualtostring:]: unrecognized selector sent to instance 0x5746830

如果我再次开张,表上的观点是负荷的,但表中没有数据。

该信息在<条码>上显示([部分内容为:@”项目]:

program received signal SIGABRT

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    classelement = elementName;
    if ([elementName isEqualtostring:@"item"])
    {
        itemselected = YES;
        multitle = [[NSMutableString alloc]init];
        mullink = [[NSMutableString alloc]init];
    }
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedname:(NSString *)qName
{
    if ([elementName isEqualToString:@"item"])
    {
        itemselected = NO;
        [titlearray addObject:multitle];
        [linkarray addObject:mullink];
        [multitle release];
        [mullink release];

        [self.tbl reloadData];
    }
}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if (itemselected)
    {
        if ([classelement isEqualToString:@"title"]) 
        {
            NSLog(@"%@",string);
            [multitle appendString:multitle];
        }
        else if([classelement isEqualToString:@"link"])
        {
            [multitle appendString:string];
        }
    }
}
最佳回答

最后,我要谈谈这个问题。 我已采用了两个<代码>。 NSMutable Arrays and two NSMutableStrings and I supplemented the items to the strings, and subsequently those strings I supplemented to the two ranges.

(void)viewDidLoad
{

    titlearray = [[NSMutableArray alloc]init];
    linkarray = [[NSMutableArray alloc]init];

    NSString *rssaddress =@"http://www.greenday.com/rss";
    NSURL *url = [NSURL URLWithString:rssaddress];
    xmlparser = [[NSXMLParser alloc]initWithContentsOfURL:url];
    [xmlparser setDelegate:self];
    [xmlparser parse];


    [super viewDidLoad];
}

(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{

    classelement = elementName;



    if([elementName isEqualToString:@"item" ])
    {
        itemselected = YES;
        titlestrng = [[NSMutableString alloc]init];
        linkstrng = [[NSMutableString alloc]init];

    }

}

(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{

    if([elementName isEqualToString:@"item" ])
    {
        itemselected = NO;
        [titlearray addObject:titlestrng];
        [linkarray addObject:linkstrng];


        [titlestrng release];
        [linkstrng release];


        [self.tb reloadData];
    }
}


(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{

    if(itemselected)
    {
        if([classelement isEqualToString:@"title"])
        {
            [titlestrng appendString: string];
                    NSLog(@"%@",titlestrng);
        }

        else if ([classelement isEqualToString:@"link"])
        {
            [linkstrng appendString:string];
            NSLog(@"%@",linkstrng);

        }
    }
}
问题回答

如果你从一个网站上直接阅读,那么你就更有可能获得“无效”特性。 一旦区长看到这些无效特性,就会坠毁。 我建议研究使用“HPPLE Parser”。 如果无效特性出现,它就会做得更好,并赢得坠毁。

Hpple information here: http://blog.objectgraph.com/index.php





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签