Share on Google+Share on Google+

Ravi Vora
0 Answer(s)      4 years and 11 months ago
Posted in : XML

in .h file NSXMLParserDelegate

NSMutableArray *titlearray; NSMutableArray *descarray; NSMutableArray *linkarray; NSMutableArray *pubdatearray;

NSMutableDictionary *titledict;
NSMutableDictionary *descdict;
NSMutableDictionary *linkdict;
NSMutableDictionary *pubdatedict;
NSMutableString *currentElementValue;

.m file

- (void)viewDidLoad {
    [super viewDidLoad];

    //appDelegate = (rss2AppDelegate *)[[UIApplication sharedApplication] delegate];

    self.navigationItem.title = @"rssfeed";

    //NSURL *url = [[NSURL alloc] initWithString:@""];
    NSURL *url=[[NSURL alloc] initWithString:@""];

    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    //xmlparser *parser = [[xmlparser   alloc] initxmlparser];

    [xmlParser setDelegate:self];

    BOOL success = [xmlParser parse];

        NSLog(@"No Errors");
        NSLog(@"Error Error Error!!!");


    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

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

    if([elementName isEqualToString:@"channel"]) {
        //Initialize the array.
        titlearray=[[NSMutableArray alloc]init];
        descarray=[[NSMutableArray alloc]init];
        linkarray=[[NSMutableArray alloc]init];
        pubdatearray=[[NSMutableArray alloc]init];

        //appDelegate.rss = [[NSMutableArray alloc] init];
    else if([elementName isEqualToString:@"item"]) {

        titledict=[[NSMutableDictionary alloc]init];
        descdict= [[NSMutableDictionary alloc]init];
        linkdict=[[NSMutableDictionary alloc]init];
        pubdatedict=[[NSMutableDictionary alloc]init];
  • (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

        currentElementValue = [[NSMutableString alloc] initWithString:string];
    //  [currentElementValue appendString:string];
        currentElementValue=[NSMutableString stringWithString:string];


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

    if([elementName isEqualToString:@"item"]) {
        [titlearray addObject:[titledict valueForKey:@"title"]];
        [descarray addObject:[descdict valueForKey:@"description"]];
    //NSString *str1=[descdict valueForKey:@"description"];
    //NSLog(@"str1 = %@",str1);
    //NSArray *firstSplit = [str1 componentsSeparatedByString:@"<p><"];
    //NSLog(@"0 index =  %@",[firstSplit objectAtIndex:0]);
    [linkarray addObject:[linkdict valueForKey:@"link"]];
    [pubdatearray addObject:[pubdatedict valueForKey:@"pubDate"]];
    } else if([elementName isEqualToString:@"title"]) { [titledict setObject:currentElementValue forKey:@"title"]; } else if([elementName isEqualToString:@"description"]) { [descdict setObject:currentElementValue forKey:@"description"]; } else if([elementName isEqualToString:@"link"]) { [linkdict setObject:currentElementValue forKey:@"link"]; } else if([elementName isEqualToString:@"pubDate"]) { [pubdatedict setObject:currentElementValue forKey:@"pubDate"]; } }


View Answers

Related Tutorials/Questions & Answers:
XmlParsing in Android
XmlParsing in Android  how can i XmlParsing in Android
xml Converting to java using JDOM
.build("C:\\Users\\h.khammash\\Desktop\\Studening workspace\\XMLParsing
Read XML using Java
Java Spring Hibernate Struts Training were to start with xml, XSD and java write a program that Implement an integrated COM client server to add two visuall studio 2010 Building a Parent Child relationship XML how i connect two page xml question struts cfg file for DispatchAction with mysql db Creating custom output using XMLUnit - MatchTracker duplicates the output data Related to XML Related to XML Reading child of child nodes in xml Reading multiple xml files Spliting Large XML and one by one Moved to Output Folder XMl and Java web services project download xml file from website using java code Download how to create an xml file in following clear format Conditional increment in xslt Conditional increment in xslt Conditional increment in xslt HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP? xml and servlets xml and servlets Question about parsing XML document with DOM in JAVA. Removal of XML header Converting PHP page with flash to JSP page without flash saving data in xml Doubt about Xstream Converter Reading xml file using dom parser in java with out using getelementby tag name xml dynamically how to change attiribute values in xml XML Schema xml xml sax parser for xml parsing xml using sax xml to html via java i want java code for this xml file...please show me.. SAX Parser for huge XML file xml parsing "opening video data error" in j2me XML to JSP mapview1 mapview searchbar searchbar jsonparsing xmlparsing retrieve multiple attribute values retrieve multiple attribute values


Advertisement null