Jump to content
Welcome to InsanelyMac Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

  • Announcements

    • Allan

      Forum Rules   04/13/2018

      Hello folks! As some things are being fixed, we'll keep you updated. Per hour the Forum Rules don't have a dedicated "Tab", so here is the place that we have our Rules back. New Users Lounge > [READ] - InsanelyMac Forum Rules - The InsanelyMac Staff Team. 
Sign in to follow this  
LooN3y

XML Parsing Done Wrong?

1 post in this topic

Recommended Posts

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?

 

 


- (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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.



×