views:

72

answers:

1

From the XML below I'm trying to retrieve the second element in the sequence. Notice the end node is the same as the start in each entry, this is making its retrieval a bit tricky.

I've tried setting a for loop at the startElementSAX function to evaluate and pick-up the Width="60" attribute. Although this will sort the data correctly it still results in the targeted property receiving the last path in the sequence. I presume it's because in order to retrieve the attribute for the node it need to be discovered first. So this is also getting sent each time. I've not been able to find a way of isolating this from happening.

I've made a trace which confirms all three paths are sent each time regardless of the start criteria. This wouldn't be a problem if I was able to be attach them to different properties.

If you want to look at the project in it's entirety it's in the Apple iPhone Dev Centre called TopSongs. You may need a password.

<itms:coverArt height="53" width="53">http://a1.phobos.apple.com/us/r1000/030/Music/7f/b0/f6/mzi.erhtxklr.53x53-50.jpg&lt;/itms:coverArt&gt;
<itms:coverArt height="60" width="60">http://a1.phobos.apple.com/us/r1000/030/Music/7f/b0/f6/mzi.erhtxklr.60x60-50.jpg&lt;/itms:coverArt&gt;
<itms:coverArt height="100" width="100">http://a1.phobos.apple.com/us/r1000/030/Music/7f/b0/f6/mzi.erhtxklr.100x100-75.jpg&lt;/itms:coverArt&gt;

This is the endElement code I have so far.

static void endElementSAX(void *parsingContext, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI) {    
iTunesRSSImporter *importer = (iTunesRSSImporter *)parsingContext;
if (importer.parsingASong == NO) return;
} else if (!strncmp((const char *)prefix, kName_Itms, kLength_Itms)) {
if (!strncmp((const char *)localname, kName_CoverArt, kLength_CoverArt)) {
importer.currentSong.coverArt60 = importer.currentString;
A: 

You are applying an arbitrary additional meaning to the XML; you have decided that you must have element #2 from the list of <itms>...</itms> elements. Since the document doesn't call that particular element out as anything different/special, you are going to have to do it yourself.

Thus, you'll need to keep the bookkeeping for doing this to externally to the parsing itself (since there is nothing in the document to indicate that #2 is any different than the rest).

The easiest way is to declare a global variable...

unsigned int coverArtIndex;

Then set it to 0 before you start parsing a group of items. Increment it every time you hit the beginning of the tag for which you want item #2 and, when it is 2, suck off the data that you want and store it somewhere. Then just skip the rest (do nothing as the SAX events are processed). When you hit the end of the group, reset coverArtIndex.

bbum
You're absolutely right, coverArt will need to incrementally indexed. I wasn't sure if this should be done within the SAX events being processed. If I understand you correctly I should be sorting this outside the SAX process and passing it in as a preformatted SAX structure and resetting the index at the end?
Jim