我阅读了一台XML,从一个角度对数据进行分类。 当我试图以另一种观点接触该物体时,该物体似乎是无效的。 先前的观点认为,国家航空航天局具有价值观。 我需要这些价值观,以形成一种 pick。 请让我知道我究竟是谁错了? 兹附上以下守则: 另一种观点认为,测试法的价值是无效的。
页: 1
NSString *soapMessage = [NSString stringWithFormat:
@"<?xml version="1.0" encoding="utf-8"?>
"
"<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/">
"
"<soap:Body>
"
"<GetCommonCodeByCatg xmlns="http://longbeach.gov/PDPropertyReg/Services/">
"
"<catg>COLOR</catg>
"
"</GetCommonCodeByCatg>
"
"</soap:Body>
"
"</soap:Envelope>
"];
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{
[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];
index =0;
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"GetCommonCodeByCatgResult"]) {
self.testArray = [[NSMutableArray alloc]init];
}
else if ([elementName isEqualToString:@"SvcCommonCode"]) {
aCategory =[[Category alloc]init];
if ([elementName isEqualToString:@"CMCode"]) {
aCategory.CMCode = [attributeDict objectForKey:@"CMCode"];
}
NSLog(@"Reading the CMCode: %@",aCategory.CMCode);
}
NSLog(@"Processing element: %@", elementName);
}
-(void)parser: (NSXMLParser *)parser foundCharacters:(NSString *)string{
if (!currentElementValue)
currentElementValue =[[NSMutableString alloc]initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing value:%@",currentElementValue);
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"GetCommonCodeByCatgResult"]) {
return;
}
if ([elementName isEqualToString:@"SvcCommonCode"]) {
[self.testArray insertObject:aCategory atIndex:index];
index =index+1;
[aCategory release];
aCategory =nil;
}
else
[aCategory setValue:currentElementValue forKey:elementName];
[currentElementValue release];
currentElementValue = nil;
NSLog(@"Item count %i",[self.testArray count]);
}