我正在使用NSXmlParser
并尝试解析这个 XML 文件:
<api>
<query>
<normalized>
<n from="new york" to="New york"/>
</normalized>
<redirects>
<r from="New york" to="New York"/>
</redirects>
<pages>
<page pageid="8210131" ns="0" title="New York">
<extract xml:space="preserve"><p><b>New York< ...
基本上这个文件很长,但我试图只复制<extract>
元素。
我NSMutableString
用这段代码通过几种方式完成了它:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
CrrentString = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[CrrentString appendString:string];
NSLog(@"%@",CrrentString);
}
-(void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
currentKey = nil;
if ([elementName isEqualToString:@"extract"]) {
CrrentString = [attributeDict objectForKey:@"extract"];
return;
}
}
但最后,这只给了我( )>
内部。NSMutableString
CrrentString