Since the happymapper google group has been closed to posting, thought I’d toss this up here.

I posted this question to the group:

I have a node that looks like this:
 <ProductVar text_id="Variable1">MyValue</ProductVar>
 <ProductVar text_id="Variable2">MySecondValue</ProductVar>

I need both the value of the attribute "text_id" and the element value
"MyValue". I was trying to use something like what I saw in the
"current weather" example:

<aws:current-condition icon="
element :current_condition, String, :tag => 'current-
condition', :attributes => {:icon => String}

Which (the example) works just fine on my system. So this is the
mapping I have:

class ItemInfo
 include HappyMapper
 tag 'ItemInfo'
 has_many :product_var, String, :tag => "ProductVar", :attributes =>
{:text_id => String}

This does not return text_id. I can return
item_info.product_var.text_id if I use "element" in place of
"has_many", but there are always going to be multiple "ProductVar"s,
so that won't work. Whenever I try to replace "element" with
"has_many", I get this error:

undefined method `attribute_nodes' for ["text_id", "Variable1"]:Array


Well, if I’d thought this through and read the code, as suggested here:
I’d have figured this out. Since I didn’t, it took the help of both the wonderful Eric Larson and Damien Le Berrigaud to point out my epic failure to read the docs (in the nicest way possible).

Eric pointed out that what I needed was to make ProductVar its own class:

From: Eric Larson
Date: October 22, 2010 10:07:13 AM CDT

Hi Sara,

When I'm happymapping, I like to create a class per each element I'm
parsing, always.

Try something like this:

class Product
 include HappyMapper
 tag 'ProductVar'
 attribute :text_id, String
 content :value

class ItemInfo
 include HappyMapper
 tag 'ItemInfo'
 has_many :products, Product

- - - -

Pseudo code... but it should be very close to working.

- Eric

Which I thought was brilliant, but then realized I didn’t have the method “content” available to me because I was using the nokogiri-happymapper gem. So off to Damien I went, to ask if he could merge in the “content” method to nokogiri-happymapper, only to have him tell me:

You can already do that with text_node. Check the spec: it "should parse text node correctly" in happymapper_spec :)

So, had I just read the docs and/or the spec, I’d have figured this out. SMRT.

Thought I’d post this just in case anyone else had the same problem.