Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly Create a Obj c class having .h and .m files only. and in that create some NSString Variables having properties like name, distance, longitude, latitude.. etc etc.</p> <p>now, the code part :-</p> <p>In didStartElement</p> <p>in restaurant tag create a Object of that class which i just told u to create(initialize the Object):-</p> <pre><code>currentElement = elementName; if([currentElement isEqualToString:@"restaurant"]) { classObj = [[MyRestaurentClass alloc]init]; } </code></pre> <p>Now In foundCharacters find the other tags like this :-</p> <pre><code>if([currentElement isEqualToString:@"name"]) { classObj.Name=[NSString stringWithFormat:@"%@",string]; NSLog(@"Name to be saved in Array :- %@",string); } if ( [currentElement isEqualToString:@"longitude"]) { classObj.longitude =[NSString stringWithFormat:@"%@",string]; } } </code></pre> <p>Now Last part in didEneElement :-</p> <p>Create a MutubaleArray in Parser Class and Add the classObj in that array in didEndElement :-</p> <pre><code>if([elementName isEqualToString:@"restaurent"]) { NSLog(@"Current element in End Element Category:- %@",currentElement); [ObjectsMutableArray addObject:classObj]; } </code></pre> <p>And that's all. u r finished with parsing ..</p> <p><strong>UPDATE</strong></p> <p>Firstly you dont have to write like this in If loop i.e. :-</p> <pre><code>- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict{ NSLog (@"At parser"); currentElement = elementName; if ([currentElement isEqualToString:@"restaurant_details"]) { if ([currentElement isEqualToString:@"total_results"]) { //NSLog(@"Element: %@", currentElement); }else if ([currentElement isEqualToString:@"restaurant"]) { restaurantObj = [[DOR_RestaurantClass alloc]init]; } } } </code></pre> <p>What i wrote in answer for didStartElement is Sufficient as didStartElement is called for Each n Every Tag.</p> <p>See Once u create a class having NSStrings acc to your XML. Just create an Object of that class and Initialize it in didStartElement. in foundCharacters you will add the Required data in the classObject variables according to the If Conditions loops. Whenever the XMlParser comes in the <code>&lt;/restaurent&gt;</code> Tag it will go in didEndElement method and there you just have to Put that classObject (object) in that Array like i did in didEndElement.</p> <p><strong>Ok Regarding your NSMutableArray, have you Initialized the Array in didStartDocument like this :-</strong></p> <ul> <li>(void)parserDidStartDocument:(NSXMLParser *)parser{ listItems = [[NSMutableArray alloc]init]; }</li> </ul> <p>I have Changed a Above Code so please read again the whole answer carefully. If u still have any doubts Text me...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload