1

I have an etree.Element that basically just looks like <Root></Root>.

I want to insert a bunch of children elements which come from children = dicttoxml(dict, root=False).

The latter gives me a number of elements without a parent, so basically doing print children gives me this:

<Child1></Child1>
<Child2></Child2>
<Child3></Child3>
<Child4></Child4>

I want to insert children into my root etree.Element so, this:

<Root>
   <Child1></Child1>
   <Child2></Child2>
   <Child3></Child3>
   <Child4></Child4>
</Root>
JackyJohnson
  • 3,106
  • 3
  • 28
  • 35
  • Have you seen http://stackoverflow.com/questions/14440375/how-to-add-an-element-to-xml-file-by-using-elementtree ? It uses the `append` method – JacobIRR May 10 '17 at 04:42
  • it seems to me `append` only works if the appended element is a single element though – JackyJohnson May 10 '17 at 04:43
  • In that case, if `children` is iterable, you could loop over it: `for c in children: root.append(c)` – JacobIRR May 10 '17 at 04:44

0 Answers0