title: How do I add a node attribute in XML using Nokogiri?
body: <p>I'm using Ruby 1.8.7 for a project. </p>
  
  <p>I need to be able to parse and modify bits of XML code for it, and I'm running into a few problems. I am using Nokogiri to do the parsing.</p>
  
  <p>I have the line:</p>
  
  <pre><code>&lt;linking-phrase-appearance id="1JDLZ0609-JFP4ZP-TH" x="346" y="207" width="39" height="14"/&gt;
  </code></pre>
  
  <p>I need to change it to:</p>
  
  <pre><code>&lt;linking-phrase-appearance id="1JDLZ0609-JFP4ZP-TH" x="346" y="207" width="39" height="14" font-color="255 0 0 255"/&gt;
  </code></pre>
  
  <p>I have code that finds the right lines to change, but when I change it nothing is written out to the output file.</p>
  
  <p>This is the code I use to change the attribute:</p>
  
  <pre><code># middle_node = id of line that needs to be changed (is unique to the line)
  appearance = @xml.xpath("/xmlns:cmap/xmlns:map/xmlns:linking-phrase-appearance-list")
     appearance.each do |node|
        if node['id'] == middle_node
           node['font-color'] = '255,0,0,255'
         end
     end 
  </code></pre>
  
  <p>I assume there is some reason why this is not working but I'm unsure as to why.</p>