在这里,我在临时字符串中得到 xml 响应。我需要从该 xml 响应中获取一个标记值。
-(void) httpDataDidFinishLoadingWithData:(NSData *)theData
{
m_activityLoaded=NO;
temp=[[NSString alloc] initWithData:[dataLoader httpData] encoding:NSUTF8StringEncoding];
NSLog(@"TEMP IS TEMP %@", temp);
parser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:temp]];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
parser.delegate=self;
[parser parse];
}
问题是 DidStartElement 在上述解析器分配后甚至没有调用并准备解析。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if(![elementName isEqual:@"Result"])
return;
woeid = [attributeDict objectForKey:@"woeid"];
NSLog(@"woeid %@", woeid);
}
我的 XML 响应是
<?xml version="1.0" encoding="UTF-8"?>
<Body><woied></woied></Body>
请帮我摆脱这些家伙。提前致谢