Hello. I'm learning to use the NSXMLParser
API for the iOS platform and so far it's very easy to use. I'm having a small problem, however, in the foundCharacters method. As I understand it, it shouldn't pick up any whitespace since the foundIgnorableWhitespace
method is supposed to catch that, but it looks like it is. Here's the my code...
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
//We're at the start of a new data feed
if([elementName isEqualToString:@"data"])
{
if(listOfTimes != nil)
[listOfTimes release];
listOfTimes = [[NSMutableArray alloc] init];
}
else if ( [elementName isEqualToString:@"start-valid-time"]) {
currentElementType = kXMLElementTime;
return;
}
else {
currentElementType = kXMLElementOther;
}
//---------------------------------------------------------------------
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(currentElementType == kXMLElementTime)
{
//We don't want anymore than three times
if ([listOfTimes count] >= 3)
return;
[listOfTimes addObject:string];
}
}
It basically stores three "time" elements in an array. The problem, however, is it seems to be picking up whitespace in the form of a newline. Here's the printout of the array in the console...
Printing description of listOfTimes:
(
"2010-08-21T22:00:00-05:00",
"\n ",
"2010-08-22T01:00:00-05:00"
)
and here's a snippet of the XML data I'm processing...
<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p3h-n40-1</layout-key>
<start-valid-time>2010-08-21T22:00:00-05:00</start-valid-time>
<start-valid-time>2010-08-22T01:00:00-05:00</start-valid-time>
<start-valid-time>2010-08-22T04:00:00-05:00</start-valid-time>
<start-valid-time>2010-08-22T07:00:00-05:00</start-valid-time>
<start-valid-time>2010-08-22T10:00:00-05:00</start-valid-time>
.
.
.
Am I misunderstanding how this works?
Thanks in advance for your help!