Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 08-23-2011, 05:26 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
kshitija is on a distinguished road
Default iPhone: Parsing multiple XMLs

Hi

I am trying to parse multiple XMLs in the same view. I can parse the 1st XML but not the 2nd one. I have pasted my XML Parsing code.



-
Code:
(void)readXML:(NSString *)valueEntered{
	
	
	NSString *soapMessage = [NSString stringWithFormat:
							 @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
							 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
							 "<soap:Body>\n"
							 "<GetCommonCodeByCatg xmlns=\"http://longbeach.gov/PDPropertyReg/Services/\">\n"
							 "<catg>%@</catg>\n"
							 "</GetCommonCodeByCatg>\n"
							 "</soap:Body>\n"
							 "</soap:Envelope>\n",valueEntered];
	NSLog(@"Soap Message%@",soapMessage);
	
	NSURL *url =[NSURL URLWithString:@"http://wwwbitdemo.longbeach.gov/PDPropertyReg/Services/CommonCode.asmx"];
	NSMutableURLRequest *theRequest =[NSMutableURLRequest requestWithURL:url];
	NSString *msgLength =[NSString stringWithFormat:@"%d",[soapMessage length]];
	
	[theRequest addValue:@"text/xml; charset =utf-8" forHTTPHeaderField:@"Content-Type"];
	[theRequest addValue:@"http://longbeach.gov/PDPropertyReg/Services/GetCommonCodeByCatg" forHTTPHeaderField:@"SOAPAction"];
	[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
	[theRequest setHTTPMethod:@"POST"];
	[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
	
	NSURLConnection *theConnection =[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
	
	if (theConnection) {
		
		
		webData = [[NSMutableData data]retain];
		
		
		
		
	}
	else {
		NSLog(@"The connection is null");
	}
	
}


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
	
	[webData setLength:0];
	
	
}


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
	NSLog(@"connection");
	
	
	
	[webData appendData:data];
	
	
	
	
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
	NSLog(@"Connection Error");
	[connection release];
	
	
	
	[webData release];
	
	
	
	
	
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
	
	NSLog(@"Done, Received bytes: %d",[webData length]);
	
	
	
	NSString *theXML =[[NSString alloc] initWithBytes:[webData mutableBytes]length:[webData length]encoding:NSUTF8StringEncoding];
	NSLog(@"XML value %@",theXML);
	[theXML release];
	
	if (xmlParser) {
		[xmlParser release];
	}
	
	
	xmlParser = [[NSXMLParser alloc]initWithData:webData];
	[xmlParser setDelegate:self];
	[xmlParser setShouldResolveExternalEntities:YES];
	[xmlParser parse];
	
	
	
	[connection release];
	[webData release];
	
	
	
	
}

- (void)parserDidStartDocument:(NSXMLParser *)parser{ 
	NSLog(@"found file and started parsing");
	
	
	propertyCategories = [[NSMutableArray alloc]init];
	
	

}


-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
	
	
	
	if ([elementName isEqualToString:@"GetCommonCodeByCatgResponse"]) {
	}
	
	if ([elementName isEqualToString:@"SvcCommonCode"]) {
		
		
		
		
		aCategory =[[Category alloc]init];
		
		aCategory.CMCodeDesc = [attributeDict objectForKey:@"CMCodeDesc"];
		
		
		
		/*		
		 if ([recordResults isEqualToString:@"COLOR"]) {
		 
		 
		 bCategory =[[Category alloc]init];
		 
		 bCategory.CMCodeDesc = [attributeDict objectForKey:@"CMCodeDesc"];
		 NSLog(@"bCateg%@",bCategory);
		 }*/
		
		
		
		
	}
	
}

-(void)parser: (NSXMLParser *)parser foundCharacters:(NSString *)string{
	
	
	if (!currentElementValue) 
		currentElementValue =[[NSMutableString alloc]initWithString:string];
	else 
		[currentElementValue appendString:string];
	
	
}

-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
	
	if ([elementName isEqualToString:@"GetCommonCodeByCatgResponse"]) {
		
		//[itemCategoryList reloadAllComponents];
		//inputValue =@"COLOR";
		//[self readXML:inputValue];
		//return;
	}
	
	if ([elementName isEqualToString:@"SvcCommonCode"]) {
		
		
		[propertyCategories addObject:aCategory.CMCodeDesc];
		[aCategory release];
		aCategory =nil;
		
		
		NSLog(@"Property%@",propertyCategories);
		
		
		
	}
	
	else 
		
		
		
		[aCategory setValue:currentElementValue forKey:elementName];
	
	
	
	
	[currentElementValue release];
	currentElementValue = nil;
	
}
kshitija is offline   Reply With Quote
Old 08-24-2011, 02:14 AM   #2 (permalink)
Token farm animal
 
sneaky's Avatar
 
Join Date: Apr 2011
Posts: 321
sneaky is on a distinguished road
Default

And when you say you can't parse the xml what does it mean exactly?

Does the app crash, does it make no attempt at parsing, does it maybe parse some of it?
sneaky is offline   Reply With Quote
Old 08-24-2011, 12:01 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
kshitija is on a distinguished road
Default

The 1st XML is parsed as expected and the data is obtained.
When a call to the 2nd XML is made, it just forms the soap message and the application terminates.
kshitija is offline   Reply With Quote
Old 08-26-2011, 01:22 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Boston, MA
Posts: 135
carbonbasednerd is on a distinguished road
Default

Quote:
Originally Posted by kshitija View Post
The 1st XML is parsed as expected and the data is obtained.
When a call to the 2nd XML is made, it just forms the soap message and the application terminates.
What error does it throw when it terminates?
carbonbasednerd is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 390
14 members and 376 guests
Absentia, bignoggins, Diligent, dre, epaga, hussain1982, LunarMoon, momolgtm, Newbie123, omagod, Paul10, pinacate, revg, skog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,860
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0