Hi all,
so here I am stuck at the simplest part (or so I thought) of my small project for this morning. The goal was to build a simple XML Parser who takes every element they encounter and add it to a dictionary that will eventually hold all key/value pairs of the xml.
So an xml like this
<xml>
<1stTag>text</1stTag>
<2ndTag>some more text</2ndTag>
</xml>
Would end up in a dictionary with 2 key/value pairs:
{
1stTag:text;
2ndTag:some more text;
}
Adopting the NSXMLParser Framework I thought that I'd just store every encountered element and texts in variables self.elementInProgress and self.textInProgress (both NSStrings). Once the Element is finished I'd add the pair to the dictionary.
So here is the .h file:
@interface MSParser : NSObject <NSXMLParserDelegate>
{
NSString *elementInProgress;
NSString *textInProgress;
NSMutableDictionary *parsedXMLDict;
}
@property (nonatomic, retain) NSString *textInProgress;
@property (nonatomic, retain) NSString *elementInProgress;
@property (nonatomic, retain) NSMutableDictionary *parsedXMLDict;
And the respective function in the implementation file:
@synthesize textInProgress, elementInProgress, parsedXMLDict;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
[self.parsedXMLDict setValue:self.textInProgress forKey:self.elementInProgress];
NSLog(@"%@",[self.parsedXMLDict valueForKey:self.elementInProgress]);
}
Now, here I am, stumped that my NSLog returns Null! And I thought this was a no-brainer. What am I missing? Both self.textInProgress and self.elementInProgress are filled correctly according to the Debugger. I can trace it down to this line where I call setValue ForKey, which again is according to documentation and has worked more than once before for me. The dictionary just doesnt take the values. According to documentation, it would only act funny, if the passed setValue was nil, which here it isn't... Any ideas?
It all looks good, not compiler errors or warnings, it just returns Null. Stumped, as I said...