title: Parse xml file with nokogiri
body: <p>I need to parse a xml file on ruby on rails, i'm using nokogiri gem to parse it.</p>
  
  <p>I can parse like this to appear the parent and his children, but its appearing like this: </p>
  
  <pre><code>PARENT: Example Parent 1
  
  CHILD: Example Children 1Example Children 2Example Children 3
  
  PARENT: Example Parent 2
  
  CHILD:
  </code></pre>
  
  <p>Why it's missing the children of the second parent node? If I call the array with a for each, it appears all the children. I did this like this:</p>
  
  <p>In the controller:</p>
  
  <pre><code>  @codes = []
      doc.xpath('//Node').each do |parent| 
         @parentN =parent.xpath('///ancestor::*/@name')
  
  
        @codes &lt;&lt; parent.xpath('Node/@name').text
  
      end
  </code></pre>
  
  <p>And the view:</p>
  
  <pre><code>&lt;% for x in 0...@parentN.count %&gt;
  
      &lt;p&gt; PARENT: &lt;%= @parentN[x]  %&gt;  &lt;/p&gt;
  
    &lt;p&gt; CHILD:  &lt;%= @codes[x] %&gt;  &lt;/p&gt;
  
      &lt;%   end %&gt;
  </code></pre>
  
  <p>How can I "connect" the parent with the childs? Presenting the parent and his children, and then other parent and childrens...</p>
  
  <p>This is my xml file:</p>
  
  <pre><code>   &lt;Report&gt;
         &lt;Node name="Example Parent 1" color="red"&gt;
            &lt;Node name="Example Children 1" color="red" rank="very high" /&gt;
            &lt;Node name="Example Children 2" color="red" rank="high" /&gt;
            &lt;Node name="Example Children 3" color="yellow" rank="moderate" /&gt;
         &lt;/Node&gt;
         &lt;Node name="Example Parent 2" color="yellow"&gt;
            &lt;Node name="Example Children 1" color="yellow" rank="moderate" /&gt;
         &lt;/Node&gt;
      &lt;/Report&gt;
  </code></pre>