-(NSMutableDictionary *)paserItmsParms:(NSString *) paramsXML{
NSMutableString *mReponseXml=[NSMutableString stringWithString:paramsXML];
NSData *data=[NSData dataWithBytes:[mReponseXml UTF8String] length:[mReponseXml length]];
itmsParamsDictinary=[[[NSMutableDictionary alloc] init] autorelease];
NSXMLParser * parser=[[NSXMLParser alloc] initWithData:data];//设置XML数据
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser setDelegate:self];
[parser parse]; //开始解析
return itmsParamsDictinary;
}
开始解析
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
currentElementName=[[NSString alloc] initWithString:elementName];
}
解析
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if([currentElementName isEqualToString:@"ParameterName"]){
resultString=[[NSString alloc] initWithString:string];
}else if([currentElementName isEqualToString:@"ParameterValue"]){
NSString * value=[[NSString alloc] initWithString:string];
[itmsParamsDictinary setValue:value forKey: resultString];
}
}
结束解析
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
currentElementName=nil;
}