<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,33 +7,32 @@ module SAXMachine
       @top_level_elements  = []
       @collection_elements = []
     end
-    
+
     def add_top_level_element(name, options)
       @top_level_elements &lt;&lt; ElementConfig.new(name, options)
     end
-    
+
     def add_collection_element(name, options)
       @collection_elements &lt;&lt; CollectionConfig.new(name, options)
     end
-    
+
     def collection_config(name)
       @collection_elements.detect { |ce| ce.name.to_s == name.to_s }
     end
 
-    def element_config_for_attribute(name, attrs)
-      element_configs = @top_level_elements.select do |element_config|
+    def element_configs_for_attribute(name, attrs)
+      @top_level_elements.select do |element_config|
         element_config.name == name &amp;&amp;
         element_config.has_value_and_attrs_match?(attrs)
       end
-      element_configs.empty? ? nil : element_configs
     end
-  
+
     def element_config_for_tag(name, attrs)
       @top_level_elements.detect do |element_config|
         element_config.name == name &amp;&amp;
         element_config.attrs_match?(attrs)
       end
     end
-    
+
   end
 end
\ No newline at end of file</diff>
      <filename>lib/sax-machine/sax_config.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,12 +3,12 @@ require &quot;nokogiri&quot;
 module SAXMachine
   class SAXHandler &lt; Nokogiri::XML::SAX::Document
     attr_reader :object
-    
+
     def initialize(object)
       @object = object
       @parsed_configs = {}
     end
-    
+
     def characters(string)
       if parsing_collection?
         @collection_handler.characters(string)
@@ -16,88 +16,99 @@ module SAXMachine
         @value &lt;&lt; string
       end
     end
-    
+
     def cdata_block(string)
       characters(string)
     end
-    
+
     def start_element(name, attrs = [])
       @name   = name
       @attrs  = attrs
-      
+
       if parsing_collection?
         @collection_handler.start_element(@name, @attrs)
-        
+
       elsif @collection_config = sax_config.collection_config(@name)
         @collection_handler = @collection_config.handler
         @collection_handler.start_element(@name, @attrs)
-        
-      elsif @element_config = sax_config.element_config_for_attribute(@name, @attrs)
-        parse_element_attribute
-        
+
+      elsif (element_configs = sax_config.element_configs_for_attribute(@name, @attrs)).any?
+        parse_element_attributes(element_configs)
+        set_element_config_for_element_value
+
       else
-        @value = &quot;&quot;
-        @element_config = sax_config.element_config_for_tag(@name, @attrs)
+        set_element_config_for_element_value
       end
     end
-    
+
     def end_element(name)
       if parsing_collection? &amp;&amp; @collection_config.name == name
         @object.send(@collection_config.accessor) &lt;&lt; @collection_handler.object
         reset_current_collection
-        
+
       elsif parsing_collection?
         @collection_handler.end_element(name)
-        
+
       elsif characaters_captured? &amp;&amp; !parsed_config?
         mark_as_parsed
         @object.send(@element_config.setter, @value)
       end
-      
+
       reset_current_tag
     end
-    
+
     def characaters_captured?
       !@value.nil? &amp;&amp; !@value.empty?
     end
-    
+
     def parsing_collection?
       !@collection_handler.nil?
     end
-    
-    def parse_element_attribute
-      unless parsed_config?
-        mark_as_parsed
-        @element_config.each do |config|
-          @object.send(config.setter, config.value_from_attrs(@attrs))
+
+    def parse_collection_instance_attributes
+      instance = @collection_handler.object
+      @attrs.each_with_index do |attr_name,index|
+        instance.send(&quot;#{attr_name}=&quot;, @attrs[index + 1]) if index % 2 == 0 &amp;&amp; instance.methods.include?(&quot;#{attr_name}=&quot;)
+      end
+    end
+
+    def parse_element_attributes(element_configs)
+      element_configs.each do |ec|
+        unless parsed_config?(ec)
+          @object.send(ec.setter, ec.value_from_attrs(@attrs))
+          mark_as_parsed(ec)
         end
       end
-      
       @element_config = nil
     end
-    
-    def mark_as_parsed
-      # TODO: make this code not suck like this
-      @parsed_configs[@element_config] = true unless (@element_config.respond_to?(:collection?) &amp;&amp; @element_config.collection?) || 
-        (@element_config.class == Array &amp;&amp; @element_config.first.collection?)
+
+    def set_element_config_for_element_value
+      @value = &quot;&quot;
+      @element_config = sax_config.element_config_for_tag(@name, @attrs)
     end
-    
-    def parsed_config?
-      @parsed_configs[@element_config]
+
+    def mark_as_parsed(element_config=nil)
+      element_config ||= @element_config
+      @parsed_configs[element_config] = true unless element_config.collection?
+    end
+
+    def parsed_config?(element_config=nil)
+      element_config ||= @element_config
+      @parsed_configs[element_config]
     end
-    
+
     def reset_current_collection
       @collection_handler = nil
       @collection_config  = nil
     end
-    
+
     def reset_current_tag
       @name   = nil
       @attrs  = nil
       @value  = nil
       @element_config = nil
     end
-    
+
     def sax_config
       @object.class.sax_config
     end</diff>
      <filename>lib/sax-machine/sax_handler.rb</filename>
    </modified>
    <modified>
      <diff>@@ -232,6 +232,25 @@ describe &quot;SAXMachine&quot; do
           document.second.should be_nil
         end
       end
+      
+      describe &quot;when desiring both the content and attributes of an element&quot; do
+        before :each do
+          @klass = Class.new do
+            include SAXMachine
+            element :link
+            element :link, :value =&gt; :foo, :as =&gt; :link_foo
+            element :link, :value =&gt; :bar, :as =&gt; :link_bar
+          end
+        end
+
+        it &quot;should parse the element and attribute values&quot; do
+          document = @klass.parse(&quot;&lt;link foo='test1' bar='test2'&gt;hello&lt;/link&gt;&quot;)
+          document.link.should == 'hello'
+          document.link_foo.should == 'test1'
+          document.link_bar.should == 'test2'
+        end
+      end
+      
     end
   end
   </diff>
      <filename>spec/sax-machine/sax_document_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e66d6e429cb260c396c3f799e3f2d5d4b8238ed6</id>
    </parent>
  </parents>
  <author>
    <name>Michael Moen</name>
    <email>michael@underpantsgnome.com</email>
  </author>
  <url>http://github.com/pauldix/sax-machine/commit/c7c648255cf1b4cbdd27d5277a2ed2288e2397dc</url>
  <id>c7c648255cf1b4cbdd27d5277a2ed2288e2397dc</id>
  <committed-date>2009-05-30T07:19:50-07:00</committed-date>
  <authored-date>2009-05-29T09:27:44-07:00</authored-date>
  <message>cherry-pick bd152b5331c5ef10ddc854ad0c17ab0a57ba643c from benaskins to resolve the attributes and value issue
(cherry picked from commit 44e031cf697f634117e5aa683d98dadddf389eb5)</message>
  <tree>b43882c92b40cc5262cbb9549efbdb593fcd651a</tree>
  <committer>
    <name>Paul Dix</name>
    <email>paul@pauldix.net</email>
  </committer>
</commit>
