title: Edit XML with Ruby
body: <p>I'm trying to edit an XML file and replace strings with ruby variables.
  For now this is my code :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="US-ASCII"?&gt;
  &lt;Standart-Profile&gt;
      &lt;class1&gt;
          &lt;class2&gt;
              &lt;class3&gt;
                 &lt;value1&gt;old_A&lt;/value2&gt;
                 &lt;value1&gt;old_B&lt;/value2&gt;
                 &lt;value1&gt;old_C&lt;/value2&gt;
              &lt;/class3&gt;
          &lt;/class2&gt;
      &lt;/class1&gt;
  &lt;/Standart-Profile&gt;
  </code></pre>
  
  <p>And this is the Ruby file :</p>
  
  <pre class="lang-ruby prettyprint-override"><code>require "rexml/text"
  require 'rexml/document'
  include REXML
  
  def generate_2
      ...
  end
  
  def generate_1
      ...
  end
  
  
  File.open('Standart-Profile.xml') do |config_file|
    config = Document.new(config_file)
    config.root.elements['old_A'].text = 'generate_1'
    config.root.elements['old_B'].text = 'generate_2'
    config.root.elements['old_C'].text = 'generate_1'
  
    formatter = REXML::Formatters::Default.new
    File.open('New-Profile.xml', 'w') do |result|
    formatter.write(config, result)
    end
  end
  </code></pre>
  
  <p>But I keep getting this error :</p>
  
  <pre><code>Final-Tool-Kit.rb:19:in `block in &lt;main&gt;': undefined method `text=' for nil:NilC
  lass (NoMethodError)
          from test.rb:16:in `open'
          from test.rb:16:in `&lt;main&gt;'
  </code></pre>