The problem is, what you are trying to do here cannot work. You cannot add the same element twice to an XML document without cloning it.
The following code works:
using LightXML
e1 = new_element("a")
e2 = new_element("a")
e_arr = [e1; e2]
xdoc = XMLDocument()
# create & attach a root node
xroot = create_root(xdoc, "Elements")
for elem in e_arr
add_child(xroot, elem)
end
println(xroot)
Output:
<Elements>
<a/>
<a/>
</Elements>