Привет всем им, парсинг XML-файла и сохранение в nsmutabledictionary и при получении его повторяющихся значений.
<CalculateCSResult>
<Message>Hi This is the calculated info</Message>
<Custodial>
<Income>22</Income>
<OverNights>12</OverNights>
<ExemptionAmount>425</ExemptionAmount>
<StandardDeduction>512</StandardDeduction>
<FedTaxableIncome>8569</FedTaxableIncome>
<FederalTax>245</FederalTax>
<StateTax>451</StateTax>
<FICA>451</FICA>
<NetIncome>652</NetIncome>
<NetIncomePct>412542</NetIncomePct>
</Custodial>
<NonCustodial>
<Income>842</Income>
<OverNights>652</OverNights>
<ExemptionAmount>356</ExemptionAmount>
<StandardDeduction>541</StandardDeduction>
<FedTaxableIncome>658</FedTaxableIncome>
<FederalTax>412</FederalTax>
<StateTax>142</StateTax>
<FICA>652</FICA>
<NetIncome>696</NetIncome>
<NetIncomePct>96896</NetIncomePct>
</NonCustodial>
<TaxYear>523</TaxYear>
<ChilsSupportAmt>652</ChilsSupportAmt>
<CutodialChildTaxCredit>652</CutodialChildTaxCredit>
<Alerts>xmlxml</Alerts>
</CalculateCSResult>
#import "ResultParser.h"
@implementation ResultParser
@synthesize calcResult;
NSMutableDictionary *tempDict;
-(void)parse:(NSURL *)url {
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
tempDict = [[NSMutableDictionary alloc]init];
[xmlParser setDelegate:self];
if(![xmlParser parse])
NSLog(@"Error Error Error!!!");
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"CalculateCSResult"]) {
calcResult = [[NSMutableDictionary alloc] init];
}
}
- (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:@"CalculateCSResult"]) {
return;
}else if([elementName isEqualToString:@"Message"]) {
[calcResult setObject:currentElementValue forKey:elementName];
}else if([elementName isEqualToString:@"Income"] ||
[elementName isEqualToString:@"OverNights"] ||
[elementName isEqualToString:@"ExemptionAmount"] ||
[elementName isEqualToString:@"StandardDeduction"] ||
[elementName isEqualToString:@"FedTaxableIncome"] ||
[elementName isEqualToString:@"FederalTax"] ||
[elementName isEqualToString:@"StateTax"] ||
[elementName isEqualToString:@"FICA"] ||
[elementName isEqualToString:@"NetIncome"] ||
[elementName isEqualToString:@"NetIncomePct"]) {
[tempDict setObject:currentElementValue forKey:elementName];
}else if([elementName isEqualToString:@"NonCustodial"] || [elementName isEqualToString:@"Custodial"]) {
[calcResult setObject:tempDict forKey:elementName];
[tempDict removeAllObjects];
}else if([elementName isEqualToString:@"TaxYear"]) {
[calcResult setObject:currentElementValue forKey:elementName];
}else if([elementName isEqualToString:@"ChilsSupportAmt"]) {
[calcResult setObject:currentElementValue forKey:elementName];
}else if([elementName isEqualToString:@"CutodialChildTaxCredit"]) {
[calcResult setObject:currentElementValue forKey:elementName];
}else if([elementName isEqualToString:@"Alerts"]) {
[calcResult setObject:currentElementValue forKey:elementName];
}
[currentElementValue release];
currentElementValue = nil;
}
- (void)dealloc {
[tempDict release];
[calcResult release];
[super dealloc];
}
@end
и после синтаксического анализа и сохранения словаря calcResult в resDict в другом классе и отображения, как показано ниже.
NSLog(@" message = %@",[resDict objectForKey:@"Message"]);
NSMutableDictionary *custDict =(NSMutableDictionary *)[resDict objectForKey:@"Custodial"];
NSLog(@" Income = %@",[custDict objectForKey:@"Income"]);
NSLog(@" OverNights = %@",[custDict objectForKey:@"OverNights"]);
NSLog(@" ExemptionAmount = %@",[custDict objectForKey:@"ExemptionAmount"]);
NSLog(@" StandardDeduction = %@",[custDict objectForKey:@"StandardDeduction"]);
NSLog(@" FedTaxableIncome = %@",[custDict objectForKey:@"FedTaxableIncome"]);
NSLog(@" FederalTax = %@",[custDict objectForKey:@"FederalTax"]);
NSLog(@" StateTax = %@",[custDict objectForKey:@"StateTax"]);
NSLog(@" FICA = %@",[custDict objectForKey:@"FICA"]);
NSLog(@" NetIncome = %@",[custDict objectForKey:@"NetIncome"]);
NSLog(@" NetIncomePct = %@",[custDict objectForKey:@"NetIncomePct"]);
NSMutableDictionary *ncustDict =(NSMutableDictionary *)[resDict objectForKey:@"NonCustodial"];
NSLog(@" Income = %@",[ncustDict objectForKey:@"Income"]);
NSLog(@" OverNights = %@",[ncustDict objectForKey:@"OverNights"]);
NSLog(@" ExemptionAmount = %@",[ncustDict objectForKey:@"ExemptionAmount"]);
NSLog(@" StandardDeduction = %@",[ncustDict objectForKey:@"StandardDeduction"]);
NSLog(@" FedTaxableIncome = %@",[ncustDict objectForKey:@"FedTaxableIncome"]);
NSLog(@" FederalTax = %@",[ncustDict objectForKey:@"FederalTax"]);
NSLog(@" StateTax = %@",[ncustDict objectForKey:@"StateTax"]);
NSLog(@" FICA = %@",[ncustDict objectForKey:@"FICA"]);
NSLog(@" NetIncome = %@",[ncustDict objectForKey:@"NetIncome"]);
NSLog(@" NetIncomePct = %@",[ncustDict objectForKey:@"NetIncomePct"]);
NSLog(@" TaxYear = %@",[resDict objectForKey:@"TaxYear"]);
NSLog(@" ChilsSupportAmt = %@",[resDict objectForKey:@"ChilsSupportAmt"]);
NSLog(@" CutodialChildTaxCredit = %@",[resDict objectForKey:@"CutodialChildTaxCredit"]);
NSLog(@" Alerts = %@",[resDict objectForKey:@"Alerts"]);
проблема в том, что она не отображает детали депозита ... для депозитарных и нестандартных услуг отображаются данные нестандартного режима ...
, пожалуйста, помогите мне
спасибо