title: Nokogiri and XML Formatting When Inserting Tags
body: <p>I'd like to use Nokogiri to insert nodes into an XML document. Nokogiri uses the <code>Nokogiri::XML::Builder</code> class to insert or create new XML.</p>
  
  <p>If I create XML using the <code>new</code> method, I'm able to create nice, formatted XML:</p>
  
  <pre><code>builder = Nokogiri::XML::Builder.new do |xml|
    xml.product {
      xml.test "hi"
    }
  end
  
  puts builder
  </code></pre>
  
  <p>outputs the following:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;product&gt;
    &lt;test&gt;hi&lt;/test&gt;
  &lt;/product&gt;       
  </code></pre>
  
  <p>That's great, <em>but</em> what I want to do is add the above XML to an existing document, not create a new document. According to the Nokogiri documentation, this can be done by using the Builder's <code>with</code> method, like so:</p>
  
  <pre><code>builder = Nokogiri::XML::Builder.with(document.at('products')) do |xml|
    xml.product {
      xml.test "hi"
    }
  end
  
  puts builder
  </code></pre>
  
  <p>When I do this, however, the XML all gets put into a single line with no indentation. It looks like this:</p>
  
  <pre><code>&lt;products&gt;&lt;product&gt;&lt;test&gt;hi&lt;/test&gt;&lt;/product&gt;&lt;/products&gt;
  </code></pre>
  
  <p>Am I missing something to get it to format correctly?</p>