Iterating over a two level structure using nested iterators
<p>I have the following two level <code>XML</code> structure. A list of boxes, each containing a list of drawers.</p>

<pre><code>&lt;Boxes&gt;
    &lt;Box id="0"&gt;
        &lt;Drawers&gt;
            &lt;Drawer id="0"/&gt;
            &lt;Drawer id="1"/&gt;
            ...
        &lt;/Drawers&gt;
    &lt;/Box&gt;
    &lt;Box id="1"&gt;
...
    &lt;/Box&gt;
&lt;/Boxes&gt;
</code></pre>

<p>I'm parsing it using <code>StAX</code> and exposed the structure through two <code>Iterators</code>:</p>

<ol>
<li><code>BoxIterator implements Iterator&lt;Box&gt;, Iterable&lt;Box&gt;</code></li>
<li><code>Box implements Iterable&lt;Drawer&gt;</code></li>
<li><code>DrawerIterator implements Iterator&lt;Drawer&gt;</code></li>
</ol>

<p>I can then do the following:</p>

<pre><code>BoxIterator boxList;
for (Box box : boxList) {
  for (Drawer drawer : box) {
    drawer.getId()
  }
}
</code></pre>

<p>Under the hood of those <code>Iterators</code> I'm using <code>StAX</code> and both of them are accessing the same underlying <code>XMLStreamReader</code>. If I call <code>BoxIterator.next()</code> it will influence the result that will be returned on subsequent calls to <code>DrawerIterator.next()</code> because the cursor will have moved to the next box.</p>

<p>Does this break the contract of <code>Iterator</code>?
Is there a better way to iterate over a two level structure using <code>StAX</code>?</p>