NSXMLParser 读取 xml 文件时重复数据

Duplicate data while NSXMLParser reading xml-file

我有这样的xml-文件:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <background>assets/_image.png</background>
    <items>
        <item type='test1' position='6' x='123' y='456'>
            my_way
        </item>
        <item type='test2' position='8' x='456' y='123'>
            another_way
        </item>

.......................

我使用 NSXMLParser 读取它:

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if ([self.currentTag isEqualToString:@"item"]) {
        [self addItemForAttributes:self.currentAttributes withValue:string];

        NSLog(@"%@", self.items.lastObject.type);
        NSLog(@"%@", self.items.lastObject.position);
        NSLog(@"%@", NSStringFromCGPoint(self.items.lastObject.coordinate));
        NSLog(@"%@", self.items.lastObject.value);
    }
}

我将项目写入项目数组。但是当我在控制台中阅读它时,有些项目看起来是重复的。

2019-07-02 17:25:53.326939+0300 Game[1280:235820] test1
2019-07-02 17:25:53.327083+0300 Game[1280:235820] 6
2019-07-02 17:25:53.327445+0300 Game[1280:235820] {123, 456}
2019-07-02 17:25:53.327671+0300 Game[1280:235820] my_way
2019-07-02 17:25:53.327946+0300 Game[1280:235820] test1
2019-07-02 17:25:53.328021+0300 Game[1280:235820] 6
2019-07-02 17:25:53.328301+0300 Game[1280:235820] {123, 456}
2019-07-02 17:25:53.328348+0300 Game[1280:235820] 
2019-07-02 17:25:53.328991+0300 Game[1280:235820] test1
2019-07-02 17:25:53.329112+0300 Game[1280:235820] 6

如何解决?

代理方法(找到字符)调用了几次,我为它做了条件(过滤空字符串),所以它解决了我的问题。