<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,14 @@
 require &quot;spec&quot;
 require &quot;spec/rake/spectask&quot;
+require 'lib/sax-machine.rb'
 
 Spec::Rake::SpecTask.new do |t|
   t.spec_opts = ['--options', &quot;\&quot;#{File.dirname(__FILE__)}/spec/spec.opts\&quot;&quot;]
   t.spec_files = FileList['spec/**/*_spec.rb']
+end
+
+task :install do
+  rm_rf &quot;*.gem&quot;
+  puts `gem build sax-machine.gemspec`
+  puts `sudo gem install sax-machine-#{SAXMachine::VERSION}.gem`
 end
\ No newline at end of file</diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -12,12 +12,13 @@ module SAXMachine
     def characters(string)
       if @collection_parse
         @collection_parse.characters(string)
-      elsif parse_current_element?
+      elsif @capture_characters &amp;&amp; parse_current_element?
         @value ||= string
       end
     end
     
     def start_element(name, attrs = [])
+      @capture_characters = true
       if @collection_parse
         @collection_parse.start_element(name, attrs)
       else
@@ -26,9 +27,12 @@ module SAXMachine
         if collection_class = @object.class.sax_config.collection_element?(@current_element_name)
           @collection_parse = SAXHandler.new(collection_class.new)
         elsif element = @object.class.sax_config.attribute_value_element?(@current_element_name, @current_element_attrs)
-          mark_as_parsed(name)
-          @object.send(@object.class.sax_config.setter_for_element(name, @current_element_attrs), 
-            @current_element_attrs[@current_element_attrs.index(element[:value]) + 1])
+          @capture_characters = false
+          unless value_element_parsed?(element)
+            mark_as_parsed(name)
+            @object.send(@object.class.sax_config.setter_for_element(name, @current_element_attrs), 
+              @current_element_attrs[@current_element_attrs.index(element[:value]) + 1])
+          end
         end
       end
     end
@@ -65,5 +69,28 @@ module SAXMachine
       @parsed_elements.has_key?(@current_element_name) &amp;&amp;
         @parsed_elements[@current_element_name].detect {|attrs| attrs == @current_element_attrs}
     end
+    
+    def value_element_parsed?(element)
+      if @parsed_elements.has_key?(@current_element_name)
+        if element.has_key?(:with)
+          intersects = @parsed_elements[@current_element_name].collect {|attrs| element[:with] &amp; attrs}
+          current_attrs_without_value = Array.new(@current_element_attrs)
+          i = @current_element_attrs.index(element[:value])
+          current_attrs_without_value.delete_at i
+          current_attrs_without_value.delete_at i
+          intersects.detect {|attrs| attrs == current_attrs_without_value}
+        else
+          true
+        end
+      else
+        false
+      end
+    end
+    
+    def remove_value_element(element)
+      i = @current_element_attrs.index(element[:value])
+      @current_element_attrs.delete_at i
+      @current_element_attrs.delete_at i
+    end
   end
 end
\ No newline at end of file</diff>
      <filename>lib/sax-machine/sax_handler.rb</filename>
    </modified>
    <modified>
      <diff>@@ -83,7 +83,26 @@ describe &quot;SAXMachine&quot; do
         end
       end
       
-      describe &quot;using the 'with' option&quot; do
+      describe &quot;using the :with option&quot; do
+        describe &quot;and the :value option&quot; do
+          before :each do
+            @klass = Class.new do
+              include SAXMachine
+              element :link, :value =&gt; :href, :with =&gt; {:foo =&gt; &quot;bar&quot;}
+            end
+          end
+          
+          it &quot;should save the value of a matching element&quot; do
+            document = @klass.parse(&quot;&lt;link href='test' foo='bar'&gt;asdf&lt;/link&gt;&quot;)
+            document.link.should == &quot;test&quot;
+          end
+          
+          it &quot;should save the value of the first matching element&quot; do
+            document = @klass.parse(&quot;&lt;xml&gt;&lt;link href='first' foo='bar'&gt;asdf&lt;/link&gt;&lt;link href='second' foo='bar'&gt;jkl&lt;/link&gt;&lt;/xml&gt;&quot;)
+            document.link.should == &quot;first&quot;
+          end
+        end
+        
         describe &quot;with only one element&quot; do
           before :each do
             @klass = Class.new do</diff>
      <filename>spec/sax-machine/sax_document_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5878aae7627c5ac2bf0fef24cd3c654433633355</id>
    </parent>
  </parents>
  <author>
    <name>Paul Dix</name>
    <email>paul@pauldix.net</email>
  </author>
  <url>http://github.com/pauldix/sax-machine/commit/aaf03a441f46381748a7511deb7a8b030e7845b5</url>
  <id>aaf03a441f46381748a7511deb7a8b030e7845b5</id>
  <committed-date>2009-01-13T13:43:44-08:00</committed-date>
  <authored-date>2009-01-13T13:43:44-08:00</authored-date>
  <message>added spec and fix for combining :value and :with options on element. wired up a rake task to build and install gem locally.</message>
  <tree>aaec906dcce6f8658e811466243550748eeeab8c</tree>
  <committer>
    <name>Paul Dix</name>
    <email>paul@pauldix.net</email>
  </committer>
</commit>
