Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4557116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:27:46+00:00 2026-05-21T17:27:46+00:00

parssing is going well. but i a not able to get value in ‘aBook’

  • 0

parssing is going well. but i a not able to get value in ‘aBook’ object of class ‘Book'(whereas aBook have all the property of Book class like ‘id’,’iid’,’catname’,’subcatname’,’url’i.e declared and retained ). what to do get values in aBook?

here is output in gdb :

  2011-04-28 15:08:12.046 XML[7053:20b] Processing Element: Table
2011-04-28 15:08:12.047 XML[7053:20b] Processing Value: 


2011-04-28 15:08:12.048 XML[7053:20b] Processing Element: id
2011-04-28 15:08:12.048 XML[7053:20b] Processing Value: 

    1
2011-04-28 15:08:12.049 XML[7053:20b] Processing Value: 

2011-04-28 15:08:12.050 XML[7053:20b] Processing Element: catname
2011-04-28 15:08:12.050 XML[7053:20b] Processing Value: 
    Birthday
2011-04-28 15:08:12.051 XML[7053:20b] Processing Value: 

2011-04-28 15:08:12.051 XML[7053:20b] Processing Element: iid
2011-04-28 15:08:12.051 XML[7053:20b] Processing Value: 
    1
2011-04-28 15:08:12.052 XML[7053:20b] Processing Value: 

2011-04-28 15:08:12.052 XML[7053:20b] Processing Element: subcatname
2011-04-28 15:08:12.052 XML[7053:20b] Processing Value: 
    card1
2011-04-28 15:08:12.053 XML[7053:20b] Processing Value: 

2011-04-28 15:08:12.053 XML[7053:20b] Processing Element: url
2011-04-28 15:08:12.053 XML[7053:20b] Processing Value: 
    http://www.orkutpapa.com/scraps/happy-birthday-card-2-3.jpg
2011-04-28 15:08:12.054 XML[7053:20b] Processing Value: 
  

here id my code:

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

    if([elementName isEqualToString:@"NewDataSet"]) {
        //Initialize the array.
    appDelegate.books = [[NSMutableArray alloc] init];
    }
    else if([elementName isEqualToString:@"Table"]) {
        aBook = [[Book alloc] init];

    }
    NSLog(@"Processing Element: %@", elementName);
}

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

    if(!currentElementValue) 
        currentElementValue = [[NSMutableString alloc] initWithString:string];
    else 
    [currentElementValue appendString:string];

    NSLog(@"Processing Value: %@", currentElementValue);

}

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

    if([elementName isEqualToString:@"Table"]) {
        [appDelegate.books addObject:aBook];

        [aBook release];
        aBook = nil;
    }

    else if([elementName isEqualToString:@"catname"])
    {
        [aBook setValue:currentElementValue forKey:@"catname"];
       NSLog(@"elementName for catname....%@",currentElementValue);
        NSLog(@"aBook for catname....%@",aBook);
    }
    else if([elementName isEqualToString:@"subcatname"])
    {
        [aBook setValue:currentElementValue forKey:@"subcatname"];
        NSLog(@"elementName for catname....%@",currentElementValue);
        NSLog(@"aBook for catname....%@",aBook);
    }

    else if ([elementName isEqualToString:@"url"]) {
            [aBook setValue:currentElementValue forKey:@"url"];

        // [aBook setValue:currentElementValue forKey:elementName];
        NSLog(@"elementName for url....%@",currentElementValue);
        NSLog(@"aBook for url....%@",aBook);    
    }
        [currentElementValue release];
    currentElementValue = nil;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T17:27:47+00:00Added an answer on May 21, 2026 at 5:27 pm

    Here is the xml code I would use:

    <?xml version="1.0"?>
    <elements>
    <element id="1" catname="Birthday" iid="1" subcatname="card1" url="http://www.orkutpapa.com/scraps/happy-birthday-card-2-3.jpg" />
    </elements>
    

    Using an XML format above, ‘elements’ contains all of your xml records. ‘element’ represents one record with the following variables: id, catname, iid, subcatname, and url. You can change these to your preference, but pay attention to these variable names. This is how you will call the data when parsing.

    You need to make a NSURLConnection somewhere. For example, this can be in response to a UITouch or placed in viewWillAppear. I am going to assume that you know how to make this connection, but it should contain the following methods:

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    

    This method should reset the data because a incomplete response was received.

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    

    This method is were you can append your data to an NSMutableData

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    

    This should handle errors, release the connection, and release the NSMutableData.

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    

    This method should call startParsingData and release the conneciton.

    Now for the part you are probably interested in (sorry if you knew the NSURLConnection references above), how to parse the data:

    - (void)startParsingData
    {
        NSXMLParser *myDataParser = [[NSXMLParser alloc] initWithData:receivedFriendData];
        myDataParser.delegate = self;
        [myDataParser parse];
        [myDataParser release];
        [myNSMutableData release];
    }
    

    In this method, you should initialize the data parser and assign the delegate. Make sure you assign the NSXMLParserDelegate protocol to your class.

    - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
    {
        if ([elementName isEqualToString:@"element"])
        {
    
            NSString *url = [NSString stringWithFormat:@"%@", [attributeDict objectForKey:@"url"]];
    
            // Now do with your URL as you please =) 
    
        }
    } 
    

    Notice that attributeDict calls objectForKey. This key should match the variable name in the xml file that you want to call and use. Also notice that elementName (‘element’) matches the record name in the xml file.

    Let me know if this helps or if you have any additional questions!

    Cheers,
    Evan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not parsing the parameters in the beginning but parse the input string read from
Well I'm having a hell of a time trying to get my CPU down
This is not exactly a question, because in this moment I'm not able to
I'm going through the Django book and I'm currently on chapter 10 . I'm
My title is probably not really describing the problem real well. I do not
I am parsing an arbitrary length byte array that is going to be passed
Yesterday while going through this question, I found a curious case of passing and
Parsing the string message seems bad. Or was this exception not meant to be
I have a BSjax class that I wrote that lets me make async calls
I'm going through the w3cschools XSLT tutorial, and I am at this page: xsl-if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.