iPhone에서 내 View의 필드를 채우기 위해 두 개의 다른 XML에서 데이터를 읽으려고합니다.iPhone : 동일한보기에서 여러 XML에 액세스하는 방법
동일한보기에서 여러 XML을 읽을 수있는 방법이 있습니까? 나는 하나의 XML을 읽고 파싱 할 수있다.
덕분에 다른 문자열 요소를 구문 분석을 isParsingNextString 부울, 이름을 을 사용하여 NSXML 파서
-(void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response{
[webData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
[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");
//colorTypes = [[NSMutableArray alloc]init];
propertyCategories = [[NSMutableArray alloc]init];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary
*)attributeDict{
if ([elementName isEqualToString:@"GetCommonCodeByCatgResult"]) {
}
if ([elementName isEqualToString:@"SvcCommonCode"]) {
aCategory =[[Category alloc]init];
aCategory.CMCodeDesc = [attributeDict objectForKey:@"CMCodeDesc"];
}
}
-(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:@"GetCommonCodeByCatgResult"]) {
[itemCategoryList reloadAllComponents];
//[colorList reloadAllComponents];
return;
}
if ([elementName isEqualToString:@"SvcCommonCode"]) {
[propertyCategories addObject:aCategory.CMCodeDesc];
//[colorTypes addObject: aCategory.CMCodeDesc];
[aCategory release];
aCategory =nil;
}
else
[aCategory setValue:currentElementValue forKey:elementName];
[currentElementValue release];
currentElementValue = nil;
}
어떤 XML 구문 분석기를 사용합니까? XML을 파싱하기 위해 어떤 코드를 사용합니까? 이 정보가 없으면 누군가가이 질문에 답할 가능성이 매우 낮습니다. –
코드를 추가했습니다 – Katy