Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

XML Parsing Done Wrong?

LooN3yLooN3y Posts: 119Registered Users
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.
Sign In or Register to comment.