title: Dataweave - Loop in-depth mapping XML
body: <p>I have a <code>XML</code> <code>payload</code> that contains the following example:</p>
  
  <pre><code>&lt;Example&gt;
      &lt;Brand&gt;
          &lt;Id&gt;987S&lt;/Id&gt;
          &lt;logo&gt;circle&lt;/logo&gt;
          &lt;Item&gt;
              &lt;Name&gt;cologne1&lt;/Name&gt;
              &lt;Item&gt;
                  &lt;Name&gt;Bosque&lt;/Name&gt;
              &lt;/Item&gt;
          &lt;/Item&gt;
          &lt;Item&gt;
              &lt;Name&gt;t-Shirt&lt;/Name&gt;
          &lt;/Item&gt;
      &lt;/Brand&gt;
      &lt;Brand&gt;
          &lt;Id&gt;877823C&lt;/Id&gt;
          &lt;logo&gt;circle&lt;/logo&gt;
          &lt;Item&gt;
              &lt;Name&gt;t-Shirt2&lt;/Name&gt;
              &lt;Item&gt;
                  &lt;Name&gt;t-Shirt black&lt;/Name&gt;
                  &lt;Item&gt;
                      &lt;Name&gt;t-Shirt black with logo&lt;/Name&gt;
                  &lt;/Item&gt;
              &lt;/Item&gt;
          &lt;/Item&gt;
      &lt;/Brand&gt;
  &lt;/Example&gt;
  </code></pre>
  
  <p>The <code>XML</code> is divided into:</p>
  
  <ul>
  <li>Example as <strong>root node</strong>
  
  <ul>
  <li>Brand Objects
  
  <ul>
  <li><strong>Item Objects: Those Items can also contains more Items</strong></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>I get this structure randomly until <strong>3 levels in-depth per Item</strong>.</p>
  
  <p>The output expected is all Items in the same level into a parent node:</p>
  
  <pre><code>&lt;Supermarket&gt;
      &lt;Item&gt;
          &lt;BarValue&gt;cologne1&lt;/BarValue&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;BarValue&gt;Bosque&lt;/BarValue&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;BarValue&gt;t-Shirt&lt;/BarValue&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;BarValue&gt;t-Shirt2&lt;/BarValue&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;BarValue&gt;t-Shirt black&lt;/BarValue&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;BarValue&gt;t-Shirt black with logo&lt;/BarValue&gt;
      &lt;/Item&gt;
  &lt;/Supermarket&gt;
  </code></pre>
  
  <p>Is there a way to loop the XML file dynamically with Dataweave? </p>