How to insert children of one xml node in another xml node with python
<p>I have follwing xml file:</p>

<pre><code>&lt;root&gt;
 &lt;nodeA&gt;
  &lt;childrens_A&gt;
 &lt;/nodeA&gt;
 &lt;nodeB&gt;
  &lt;childrens_B&gt;
 &lt;/nodeB&gt;
 &lt;nodeA&gt;
  &lt;childrens_A&gt;
 &lt;/nodeA&gt;
 &lt;nodeB&gt;
  &lt;childrens_B&gt;
 &lt;/nodeB&gt;
&lt;/root&gt;
</code></pre>

<p>I want get something like</p>

<pre><code>&lt;root&gt;
 &lt;nodeA&gt;
  &lt;childrens_A&gt;
  &lt;childrens_B&gt;
 &lt;/nodeA&gt;
 &lt;nodeA&gt;
  &lt;childrens_A&gt;
  &lt;childrens_B&gt;
 &lt;/nodeA&gt;
&lt;/root&gt;
</code></pre>

<p>Numbers of nodes A and B equal.
I can import only from standard python library. I cannot import <code>lxml</code> because access restriction. So i want be limited <code>from xml.etree import ElementTree as et</code></p>

<p>My code is:</p>

<pre><code>from xml.etree import ElementTree as et
tree = et.parse(path_in)
root = tree.getroot()
for child in root.gethcildren()
  if child.tag == "nodeA"
     #insert children of nodeB in nodeA

tr.write(path_out)
</code></pre>

<p>Thanks in advance!</p>

<p>Looks like i find solution:</p>

<pre><code>from xml.etree import ElementTree as et

tr = et.parse(path_in)
    root = tr.getroot()
    for child in root.getchildren():
        if child.tag == 'nodeB':
            sub = child.getchildren()
            i = root.getchildren().index(child)
            root.getchildren()[i - 1].extend(sub)
tr.write(path_out)
</code></pre>

<p>Hope once this answer can  help to somebody.</p>

python xml python-2.7