这是一个简单的 XML:
<MSG>
<ID>123<ID>
<Node>
<ID>456<ID>
</Node>
</MSG>
我有一个解析器,它是子类ParentParser
并实现NSXMLParserDelegate
ParentParser
是这样的:
- (id)initWithXmlString:(NSString *)xmlString
{
if ( (self = [super init]) ) {
NSString *str = [[NSString alloc] initWithString:xmlString];
self.xml = str;
[str release];
self.storingData = NO;
self.receiveString = [NSMutableString string];
self.elementsToParse = [NSArray array];
}
return self;
}
这就是我解析 XML 的方式:
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{
if (self.m_oMyObject) {
if (self.storingData) {
NSString *tempStr = [self.receiveString stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[self.receiveString setString:@""];
if ([elementName isEqualToString:kID]) {
//Go in twice
}
//============ Code skips ===================
如您所见,kID
, StringID
已被解析两次。但我想拥有标签内的123
唯一,而不是,我该如何解决?谢谢。456
<Node>