title: How to retrieve all the nodes of an xml using xml::libxml in perl?
body: <p>I have an xml file like this "file.xml</p>
  
  <pre><code>  &lt;tables&gt;
          &lt;table&gt;
                  &lt;name&gt;abc&lt;/name&gt;
                  &lt;row&gt;12&lt;/row&gt;
                  &lt;col&gt;13&lt;/col&gt;
          &lt;table&gt;
                  &lt;name&gt;xyz&lt;/name&gt;
                  &lt;IsWrapper/&gt;
              &lt;table&gt;
                        &lt;name&gt;dummy&lt;/name&gt;
                         &lt;row&gt;121&lt;/row&gt;
                         &lt;col&gt;131&lt;/col&gt;
              &lt;/table&gt;
          &lt;/table&gt;        
      &lt;/tables&gt;
  
      I am using xml::libxml using perl. Here is the code.
  
  # ----- Parsing config XML file ---
  my $parser = XML::LibXML-&gt;new();
  my $xmldoc = $parser-&gt;parse_file ("file.xml") || die("Could not parse xml file\n");
  my $root = $xmldoc-&gt;getDocumentElement()|| die("Could not get Document Element \n");
  print "\n root = $root \n";
  if ($root-&gt;nodeType == ELEMENT_NODE) 
      {
  
          foreach my $child ($root-&gt;getChildNodes()) 
          { 
              #print "\n my child: $child \n";
              $st = $child-&gt;textContent;
              print "\n child name: $st \n";
              if ($child-&gt;nodeName eq 'table')
              {  
                  $dc = $child-&gt;nodeName;
                  print "\n node name is node: $dc\n";
                  if (defined($child-&gt;getElementsByTagName('IsWrapper',0)-&gt;item(0)))
                  { 
                      #do some thing
                  }
                  else
                  {   
                      print "\n eneterd in else part\n";
                      #do some thing        
                  }
              }
          }
      }
  </code></pre>
  
  <p>But i am not able to get the main node. I am able to get only this structure.</p>
  
  <pre><code>&lt;table&gt;
              &lt;name&gt;xyz&lt;/name&gt;
              &lt;IsWrapper/&gt;
          &lt;table&gt;
                    &lt;name&gt;dummy&lt;/name&gt;
                     &lt;row&gt;121&lt;/row&gt;
                     &lt;col&gt;131&lt;/col&gt;
          &lt;/table&gt;
      &lt;/table&gt;    
  </code></pre>
  
  <p>How can i get all the elements in the structure in the same order.</p>
  
  <p>The output should be like this</p>
  
  <pre><code>&lt;tables&gt;
  &lt;table&gt;&lt;name&gt;abc&lt;/name&gt;
      &lt;row&gt;12&lt;/row&gt;
      &lt;col&gt;13&lt;/col&gt;
      &lt;name&gt;xyz&lt;/name&gt;
          &lt;row&gt;121&lt;/row&gt;
      &lt;col&gt;131&lt;/col&gt;
          &lt;/table&gt;
   &lt;/tables&gt;  
  </code></pre>
  
  <p>How can i parse the above XML and get the below output in libxml using Perl?</p>
  
  <p>Help is very much appreciated.</p>