title: XML parsing with unique tags for sub element
body: <p>I have below xml data</p>
  
  <pre><code>xml_data = """&lt;?xml version="1.0"?&gt;
      &lt;DATA VERSION="1"&gt;
          &lt;transaction&gt;
              &lt;receiptNo&gt;123&lt;/receiptNo&gt;
              &lt;item&gt;
                  &lt;code&gt;163&lt;/code&gt;
                  &lt;price&gt;1100&lt;/price&gt;
                  &lt;qty&gt;1&lt;/qty&gt;
                  &lt;items&gt;
                      &lt;item&gt;
                          &lt;code&gt;145&lt;/code&gt;
                          &lt;price&gt;1200&lt;/price&gt;
                          &lt;qty&gt;1&lt;/qty&gt;
                          &lt;items&gt;
                              &lt;item&gt;
                                  &lt;code&gt;174&lt;/code&gt;
                                  &lt;price&gt;0&lt;/price&gt;
                                  &lt;qty&gt;1&lt;/qty&gt;
                              &lt;/item&gt;
                              &lt;item&gt;
                                  &lt;code&gt;172&lt;/code&gt;
                                  &lt;price&gt;400&lt;/price&gt;
                                  &lt;qty&gt;1&lt;/qty&gt;
                              &lt;/item&gt;
                          &lt;/items&gt;
                      &lt;/item&gt;
                      &lt;item&gt;
                          &lt;code&gt;363&lt;/code&gt;
                          &lt;price&gt;500&lt;/price&gt;
                          &lt;qty&gt;1&lt;/qty&gt;
                      &lt;/item&gt;
                  &lt;/items&gt;
              &lt;/item&gt;
              &lt;item&gt;
                  &lt;code&gt;060&lt;/code&gt;
                  &lt;price&gt;900&lt;/price&gt;
                  &lt;qty&gt;1&lt;/qty&gt;
                  &lt;items&gt;
                      &lt;item&gt;
                          &lt;code&gt;600&lt;/code&gt;
                          &lt;price&gt;0&lt;/price&gt;
                          &lt;qty&gt;1&lt;/qty&gt;
                      &lt;/item&gt;
                  &lt;/items&gt;
              &lt;/item&gt;
          &lt;/transaction&gt;
      &lt;/DATA&gt;
  """
  </code></pre>
  
  <p>I have successfully parsed it using the below code</p>
  
  <pre><code>import pandas as pd
  import xml.etree.ElementTree as ET
  
  root = ET.fromstring(xml_data)
  
  cols = ['receiptNo','code','price','qty','item_id']
  df_xml = pd.DataFrame(columns=cols)
  
  for trx in root.iter('transaction'):
      receiptNo = trx.find('receiptNo').text
  
      item_id = 0
  
      for it in trx.iter('item'):
          code = it.find('code').text
          price = it.find('price').text
          qty = it.find('qty').text
  
          item_id += 1    
  
          df_xml = df_xml.append(pd.Series([receiptNo,code,price,qty,item_id],
                                           index=cols),ignore_index=True)
  </code></pre>
  
  <p>And I get the output as below</p>
  
  <pre><code>+---+-----------+------+-------+-----+---------+
  |   | receiptNo | code | price | qty | item_id |
  +---+-----------+------+-------+-----+---------+
  | 0 |       123 |  163 |  1100 |   1 |       1 |
  | 1 |       123 |  145 |  1200 |   1 |       2 |
  | 2 |       123 |  174 |     0 |   1 |       3 |
  | 3 |       123 |  172 |   400 |   1 |       4 |
  | 4 |       123 |  363 |   500 |   1 |       5 |
  | 5 |       123 |  060 |   900 |   1 |       6 |
  | 6 |       123 |  600 |     0 |   1 |       7 |
  +---+-----------+------+-------+-----+---------+
  </code></pre>
  
  <p>my question is on the <code>item_id</code> column. what I get is a running sequence of numbers. </p>
  
  <p>I do not want a running sequence number. Instead, each sub item should have it's own running number within it's parents node.</p>
  
  <p>key explanation points, </p>
  
  <ol>
  <li>Item code <code>163</code> &amp; <code>060</code> are directly under <code>&lt;transaction&gt;</code> tag.
  Hence, each should get 1 &amp; 2 respectively.(1st Layer) <code>item_id</code> column. </li>
  <li>Item code <code>145</code> &amp; <code>600</code> are the first child of their respective
  parents node. hence, both should get 1 in the <code>layer_2</code> column.</li>
  <li>item code <code>174</code> &amp; <code>172</code> are under <code>145</code>. these are the grand
  children alias the the 3rd layer. so it should get 1 &amp; 2
  respectively in <code>layer_3</code> column.</li>
  </ol>
  
  <p>My desired output is as below</p>
  
  <pre><code>+---+-----------+------+-------+-----+---------+---------+---------+
  |   | receiptNo | code | price | qty | item_id | layer_2 | layer_3 |
  +---+-----------+------+-------+-----+---------+---------+---------+
  | 0 |       123 |  163 |  1100 |   1 |       1 |       0 |       0 |
  | 1 |       123 |  145 |  1200 |   1 |       1 |       1 |       0 |
  | 2 |       123 |  174 |     0 |   1 |       1 |       1 |       1 |
  | 3 |       123 |  172 |   400 |   1 |       1 |       1 |       2 |
  | 4 |       123 |  363 |   500 |   1 |       1 |       2 |       0 |
  | 5 |       123 |   60 |   900 |   1 |       2 |       0 |       0 |
  | 6 |       123 |  600 |     0 |   1 |       2 |       1 |       0 |
  +---+-----------+------+-------+-----+---------+---------+---------+
  </code></pre>
  
  <p>what I think the issue is, when I run <code>trx.iter('item')</code>, all the tags with <code>&lt;item&gt;</code> are pulled together &amp; given the same sequence. irrespective whether these are under <code>&lt;items&gt;</code> tags (plural with 's').</p>
  
  <p>please guide me how to solve this.</p>