foundCharacters
呼び出されるのを止めることはできませんが、関心のある 2 つの要素の 1 つであるdidStartElement
場合は、何らかのクラス プロパティを設定し、そのクラス プロパティを調べて、それらの文字に対して何かを行うべきかどうかを判断することができます。受信した文字をすぐに返し、効果的に破棄する必要があります。elementName
foundCharacters
たとえば、これは私のパーサーの簡略化されたバージョンです。
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
// if the element name is in my NSArray of element names I care about ...
if ([self.elementNames containsObject:elementName])
{
// then initialize the variable that I'll use to collect the characters.
self.elementValue = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
// if the variable to collect the characters is not nil, then append the string
if (self.elementValue)
{
[self.elementValue appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
// if the element name is in my NSArray of element names I care about ...
if ([self.elementNames containsObject:elementName])
{
// step 1, save the data in `elementValue` here (do whatever you want here)
// step 2, reset my elementValue variable
self.elementValue = nil;
}
}
うまくいけば、これでアイデアが得られます。