Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 9, 2012, 06:57 PM   #1
loon3y
macrumors 6502a
 
Join Date: Oct 2011
XML Parsing Done Wrong?

Im making a split view product search app for the iPad, that gets the data from a web service. but I'm having trouble getting the data to show up in my master tableview controller (the small table view on the left)


is my parsing done correctly?


Code:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSString *responseString = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
    
    NSString * newStr = [NSString stringWithUTF8String:[self.responseData bytes]];
    
    [self parseXML]; 
}



- (void) parseXML 
{
    NSLog (@"parseXML");
   
    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:self.responseData];
    
    [xmlParser setDelegate:self];
    
    
    myMasterList = [[MasterList alloc] init];
    
    if (![xmlParser parse])
    {
        NSLog (@"An error occurred in the parsing");    
    }
}



- (void)parserDidStartDocument:(NSXMLParser *)parser 
{
    NSLog (@"parserDidStartDocument");
    inItemElement = NO;
}


- (void)parserDidEndDocument:(NSXMLParser *)parser 
{
    NSLog (@"parserDidEndDocument");
}


// Called when the parser encounters a start element
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict 
{
    if ([elementName isEqualToString:@"str_smartsearch"]) 
    {
        inItemElement = YES;
    }
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:50];
    capturedCharacters = [[NSMutableString alloc] initWithCapacity:250];
}


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{
    
    
    if ([elementName isEqualToString:@"description"])
    {
        myMasterList.masterDecript = capturedCharacters;
        NSLog(@" decription:%@", capturedCharacters);
        }
    if ([elementName isEqualToString:@"onhand"]) 
    {
        myMasterList.masterOnHand = capturedCharacters;
        
    }
    if ([elementName isEqualToString:@"price"])
    {
        myMasterList.masterPrice = capturedCharacters;
    }
    if ([elementName isEqualToString:@"itemno"])
    {
        myMasterList.masterItem = capturedCharacters;
        [masterArray addObject:myMasterList];
        myMasterList = nil;
   
        
    }
    
    capturedCharacters = nil;   
    
    if ([elementName isEqualToString:@"str_smartsearch"]) 
    {
     
       inItemElement = NO;
    }
    

}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string 
{
    if (capturedCharacters != nil) 
    {
        [capturedCharacters appendString:string];
   
    }
    else 
    {
        [capturedCharacters isEqual:string];
    }
    
}

I've token out the NS logs and such, to make it easier to read. i've been stuck on this for while.


all i need is for it to show up on my master tableview and iill basically be done with this app.
__________________
AppleLife
13" MacBook Pro 2.4 GHz 8 GB Ram 250 GB HD, iPhone 5/S 64GB, iPhone 4/S 64 GB, iPhone 3GS 16 GB, iPad Air 16GB, iPad 3 16 GB Wi-Fi, iPad 2 16 GB Wi-Fi, Apple TV 3
loon3y is offline   0 Reply With Quote
Old May 10, 2012, 08:36 AM   #2
Sykte
macrumors regular
 
Join Date: Aug 2010
Code:
if (capturedCharacters != nil) 
    {
        [capturedCharacters appendString:string];
   
    }
    else 
    {
        [capturedCharacters isEqual:string];
    }
What's going on with the bold section? I believe you want to instantiate a new capturedCharacters.

Hope this helps.
__________________
Looking for apple/tech news on your IPhone or IPod touch, Try out PowerFeed. 100% free.
Sykte is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Tags
ios, iphone, web service, xml, xml-parsing

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
RSS parsing help (simple) johnnyfla123 iPhone/iPad Programming 12 Nov 29, 2013 10:16 AM
parsing text similar to markdown mraheel iPhone/iPad Programming 11 Jan 30, 2013 08:47 AM
iOS app crashing while parsing XML in TBXML RookieAppler iPhone/iPad Programming 1 Jan 29, 2013 05:20 PM
parsing and displaying in tableview jennylcf iPhone/iPad Programming 2 Jan 28, 2013 06:31 AM
parsing XML in iphone? hajira iPhone 0 Sep 24, 2012 04:51 AM

Forum Jump

All times are GMT -5. The time now is 03:54 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC