Drupal FeedAPI & Feed Element Mapper Missing Unnamed Elements In Array

I really need to figure out how to title some of these things! It's quite hard to find a way to make a title, when the posts are so varied! The title seems to need being both a summary and a brief title.. bad combo.

Aaanyway... Quick problem I've been having that cost me many days of headaches. I'm hoping this will help others as well as remind me later what the problem was and how to solve it.

Basically, I'm using the FeedAPI and Feed Element Mapper in Drupal to import some data feeds and create content nodes for display in one of my sites. The thing is, my data feed is not simple RSS formatted, so it includes a bunch of other XML elements that all the parsers coming with FeedAPI are missing! Argh! I figured out a way to expose a bunch of the elements that were getting missed... but be warned, it's a bit of a hack job.

(This is a solution for people already working with FeedAPI/FEM and isn't a tutorial on the usage of either of those... sorry.)

Read more for the rest...

The Problem:
In arrays parsed by the included parsers with FeedAPI (both SimplePie and Common Syndication), anything that shows up in a feed that in an array without a name (ie: numbered elements like [0], [1], etc.) don't show up as mappable when using the Feed Element Mapper, even when they are displayed in the "Map" interface for the feed item. Sucky! (Oh, by the way, if you don't know what I'm talking about, you might just read elsewhere for info on these great Drupal modules... they're really, really great. I might post info about them later.)

So, for example, consider this array:

Array (
[title] => Some Title Here
[description] => Some Descriptive Textual Text
[options] => Array (
  [enclosures] => Array (
    [application] => Array (
       [x-shockwave-flash] => Array (
          [0] => Array (
             [description] =>  Holy crap, this was an excessively-long example!!!
(...)

In this case, the Feed Element Mapper would stop looking after the [0] element! Ugh. That just happens to be exactly what I'm looking for!

This Worked:
My solution (again, remember I'm admitting this is a total hack) is to simply delete a few characters from the parser and try again. I take absolutely NO responsibility for this being a stupid, stupid way to do this, if in fact -- as I suspect -- this is a stupid thing to do.

Install and enable SimplePie support for FeedAPI if you haven't done that yet (instructions in the module and beyond this scope.) Open up the file for the SimplePie parser in the FeedAPI module directory on your Drupal install. It ought to be something like this:

sites/all/modules/feedapi/parser_simplepie/parser_simplepie.module

I found the section that handles the parsing of "enclosures" and looked around for a bit. The offending bit of code (well, it's offensive to me, since it's causing me problems, but it might be blatantly obvious to many of you in-the-know that I'm not a PHP programmer, so I might be doing something stupid here...)

Line 127 in my copy of parser_simplepie.module:

$curr_item->options->enclosures[$type][$subtype][] = $enclosure;

OK. See that spare "[]" bit?? Well... that's where I'm at odds with this parser. In my particular case, with a KNOWN feed of data, I don't need support for multiple arrays of elements inside options->enclosures->$type->$subtype. I can simply delete the extra array assignment space and I'll only get one array of this subtype! I know for a fact that there will only ever be one of these here, so I'm good with that!! (and yes, I'm butchering the main SimplePie parser and should have instead made my own parser... but that has already burned 3 days in my attempt to get that working, so I'm done thinking along that road. Bummer, really, since that's what I really want! I digress...)

New line 127:

$curr_item->options->enclosures[$type][$subtype] = $enclosure;

Save. Upload. Refresh "Map" tab and you should see more mappable elements than you had before. Hurray!

Simple solution that now nets me something that's mappable without a spare "[0]" array at the end. Of course, there are other places where it goes even deeper and there are more ignored "[0]" arrays for FEM, but I'm just not worrying about these right now, since this solves my primary problem and I'm happy about that.

Hope this helps someone!! I've gotta run, but maybe someone who knows much better than I will drop comments to provide a more elegant solution.
Cheers!