title: How can I auto-indent XML nodes with XML::LibXML?
body: <p>I'm adding nodes to my XML document as part some in-house processing, but cannot get <a href="http://search.cpan.org/perldoc?XML%3a%3aLibXML" rel="nofollow"><code>XML::LibXML</code></a> to auto-indent the added nodes.</p>
  
  <p>I get output like the following:</p>
  
  <p>Here's what I'm currently getting with <code>$xml-&gt;toString( 1 )</code>:</p>
  
  <pre><code>                                    &lt;nested_nodes&gt;
                                          &lt;nested_node&gt;
                                          &lt;configuration&gt;A&lt;/configuration&gt;
                                          &lt;model&gt;45&lt;/model&gt;
                                          &lt;added_node&gt;
          &lt;ID&gt;
              &lt;type&gt;D&lt;/type&gt;
              &lt;serial&gt;3&lt;/serial&gt;
              &lt;kVal&gt;3&lt;/kVal&gt;
          &lt;/ID&gt;
      &lt;/added_node&gt;
  &lt;/nested_node&gt;
                                      &lt;/nested_nodes&gt;
  </code></pre>
  
  <p>What I would like to have is pretty-printed output:</p>
  
  <pre><code>                            &lt;nested_nodes&gt;
                                  &lt;nested_node&gt;
                                      &lt;configuration&gt;A&lt;/configuration&gt;
                                      &lt;model&gt;45&lt;/model&gt;
                                      &lt;added_node&gt;
                                          &lt;ID&gt;
                                              &lt;type&gt;D&lt;/type&gt;
                                              &lt;serial&gt;3&lt;/serial&gt;
                                              &lt;kVal&gt;3&lt;/kVal&gt;
                                          &lt;/ID&gt;
                                      &lt;/added_node&gt;
                                  &lt;/nested_node&gt;
                              &lt;/nested_nodes&gt;
  </code></pre>
  
  <hr>
  
  <p>The optional <code>$format</code> parameter for the <code>toString()</code> method documented in <a href="http://search.cpan.org/perldoc?XML%3a%3aLibXML%3a%3aDocument" rel="nofollow"><code>XML::LibXML::Document</code></a> doesn't seem to help.</p>