Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
iOS Development
XML Parsing Done Wrong?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Loon3y" data-source="post: 1403542" data-attributes="member: 217795"><p>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)</p><p></p><p></p><p>is my parsing done correctly?</p><p></p><p></p><p>[CODE]</p><p></p><p>- (void)connectionDidFinishLoading:(NSURLConnection *)connection</p><p>{</p><p> NSString *responseString = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];</p><p> </p><p> NSString * newStr = [NSString stringWithUTF8String:[self.responseData bytes]];</p><p> </p><p> [self parseXML]; </p><p>}</p><p></p><p></p><p></p><p>- (void) parseXML </p><p>{</p><p> NSLog (@"parseXML");</p><p> </p><p> NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:self.responseData];</p><p> </p><p> [xmlParser setDelegate:self];</p><p> </p><p> </p><p> myMasterList = [[MasterList alloc] init];</p><p> </p><p> if (![xmlParser parse])</p><p> {</p><p> NSLog (@"An error occurred in the parsing"); </p><p> }</p><p>}</p><p></p><p></p><p></p><p>- (void)parserDidStartDocument:(NSXMLParser *)parser </p><p>{</p><p> NSLog (@"parserDidStartDocument");</p><p> inItemElement = NO;</p><p>}</p><p></p><p></p><p>- (void)parserDidEndDocument:(NSXMLParser *)parser </p><p>{</p><p> NSLog (@"parserDidEndDocument");</p><p>}</p><p></p><p></p><p>// Called when the parser encounters a start element</p><p>- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict </p><p>{</p><p> if ([elementName isEqualToString:@"str_smartsearch"]) </p><p> {</p><p> inItemElement = YES;</p><p> }</p><p> capturedCharacters = [[NSMutableString alloc] initWithCapacity:50];</p><p> capturedCharacters = [[NSMutableString alloc] initWithCapacity:250];</p><p>}</p><p></p><p></p><p>- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName </p><p> namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName </p><p>{</p><p> </p><p> </p><p> if ([elementName isEqualToString:@"description"])</p><p> {</p><p> myMasterList.masterDecript = capturedCharacters;</p><p> NSLog(@" decription:%@", capturedCharacters);</p><p> }</p><p> if ([elementName isEqualToString:@"onhand"]) </p><p> {</p><p> myMasterList.masterOnHand = capturedCharacters;</p><p> </p><p> }</p><p> if ([elementName isEqualToString:@"price"])</p><p> {</p><p> myMasterList.masterPrice = capturedCharacters;</p><p> }</p><p> if ([elementName isEqualToString:@"itemno"])</p><p> {</p><p> myMasterList.masterItem = capturedCharacters;</p><p> [masterArray addObject:myMasterList];</p><p> myMasterList = nil;</p><p> </p><p> </p><p> }</p><p> </p><p> capturedCharacters = nil; </p><p> </p><p> if ([elementName isEqualToString:@"str_smartsearch"]) </p><p> {</p><p> </p><p> inItemElement = NO;</p><p> }</p><p> </p><p></p><p>}</p><p></p><p></p><p>- (void)parser:(NSXMLParser *)parser foundCharacters:(NSMutableString *)string </p><p>{</p><p> if (capturedCharacters != nil) </p><p> {</p><p> [capturedCharacters appendString:string];</p><p> </p><p> }</p><p> else </p><p> {</p><p> [capturedCharacters isEqual:string];</p><p> }</p><p> </p><p>}</p><p></p><p>[/CODE]</p><p></p><p></p><p>I've token out the NS logs and such, to make it easier to read. i've been stuck on this for while.</p><p></p><p></p><p>all i need is for it to show up on my master tableview and iill basically be done with this app.</p></blockquote><p></p>
[QUOTE="Loon3y, post: 1403542, member: 217795"] 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]; } } [/CODE] 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. [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
iOS Development
XML Parsing Done Wrong?
Top