TrimItemTitles method


#1

Hi,

I wondered why we implemented the TrimItemTitles method in the RSSChannel.m, instead of the RSSItem.m.
I suppose it’s simpler to parse all the items once the array of items has been created, but would it be possible to trim the item titles just after they are set, that is, in the parser:didStartElement:nameSpaceURI:qualifiedName:attributes: method of RSSItem.m ?

Thanks
Fred


#2

I have the same thinking as FreddyF had.
What is the reason to put the trimItemTitles method in the RSSChannel, instead of RSSItem?

We might have to manipulate not only the title but also other elements of RSSItem, such as author, link parameters, or what ever.
I feel it is better these manipulation code is in RSSItem than in RSSChannel because they are the member of RSSItem, not of RSSChannel.

BTW, item titles are actually set in the RSSItem’s parser:foundCharacters: method, not in parser:didStartElement:nameSpaceURI:qualifiedName:attributes: method.
So, RSSItem’s parser:didEndElement:namespaceURI:qualifiedName: will be the possible place to perform trimming titles.

Thanks.


#3

Hey guys,

I think it is indeed just a matter of choice. The author chose to do it in RSSChannel, just because, as FreddyF correctly mentions, once parser:didEndElement: reaches the element “channel”, the array will always be complete, and so you can trim the whole bunch in one go. It is convenient, and probably faster.

There is no restriction I can think of that holds you from doing the trimming in RSSItem. Seems to be just a matter of placing the code inside RSSItem’s implementation of parser:didEndElement:, just like QuestionDriven pointed out, to be triggered once it reaches the element “item” as in if ([elementName isEqual:@“item”]), or in other words, once the element you want to trim is available and complete.

Cheers!

Gilmar


#4

Hi,

if it’s just a matter of choice, I prefer to chose to do it in RSSItem instead of RSSChannel because parsing element into RSSItem instance is the responsibility of RSSItem, not that of RSSChannel.

Actually, in Chapter 29, “pubDate” are formatted in RSSItem’s parser:didEndElement:.
Trimming Title is one form of formatting but the author chose different way.
So, I guess there might be a particular reason to let RSSChannel do it, instead of RSSItem.

Thanks,
QuestionDriven