title: How do I search and replace nodes Nokogiri?
body: <p>I have an HTML document as a string. I parsed it using Nokogiri:</p>
  
  <pre><code>doc_str = &lt;&lt;-mydoc
    &lt;p&gt;Lorem ipsum dolor sit foo.&lt;/p&gt;
    &lt;h2&gt;Consectetur adipisicing bar&lt;/h2&gt;
    &lt;p&gt;Foo do &lt;a href="/c-foo.aspx" class = "foo" title="Foo bar."&gt;foofoo foo&lt;/a&gt;.&lt;/p&gt;
  mydoc
  
  doc = Nokogiri::HTML doc_str
  </code></pre>
  
  <p>I want to replace <code>"foo"</code> / <code>"Foo"</code> by <code>"Bar"</code> / <code>"bar"</code> in all visible texts:</p>
  
  <pre><code>desired = &lt;&lt;-mydoc
    &lt;p&gt;Lorem ipsum dolor sit bar.&lt;/p&gt;
    &lt;h2&gt;Consectetur adipisicing bar&lt;/h2&gt;
    &lt;p&gt;Bar do &lt;a href="/c-foo.aspx" class = "foo" title="Bar bar."&gt;foofoo bar&lt;/a&gt;.&lt;/p&gt;
  mydoc
  </code></pre>
  
  <p>How do I do that?</p>
  
  <p>I tried to read the <a href="http://nokogiri.org/tutorials/modifying_an_html_xml_document.html" rel="nofollow">Nokogiri tutorial</a>, which describes <code>Nokogiri::HTML::Document#at_css</code>. Using Ruby 2.0, and the latest Nokogiri, <code>doc.at_css 'h1'</code> returns <code>nil</code>, so <code>h1.content = "something"</code> is not even possible. </p>
  
  <p>Even if it worked, it would be only a first step towards solving my find and replace problem.</p>