# Convert LightXML array to XMLElement?

**URL:** <https://discourse.julialang.org/t/convert-lightxml-array-to-xmlelement/46163>\
**Category:** New to Julia\
**Created:** [September 6, 2020, 10:24pm UTC](https://discourse.julialang.org/t/convert-lightxml-array-to-xmlelement/46163 "2020-09-06T22:24:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [September 6, 2020, 10:24pm UTC](https://discourse.julialang.org/t/convert-lightxml-array-to-xmlelement/46163/1 "2020-09-06T22:24:42Z")

</div>

Hello!

Suppose I have:

```julia
using LightXML

e = new_element("a")

e_arr = [e;e]

```

How would I then go about converting e\_arr from Array{LightXML,1} to LightXML?

Kind regards

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [September 7, 2020, 5:28am UTC](https://discourse.julialang.org/t/convert-lightxml-array-to-xmlelement/46163/2 "2020-09-07T05:28:36Z")

</div>

I am using a unusual XML package in Julia or is what I am trying to do unusual?

I want to gather a lot of different XML elements, before combining them to one…

Kind regards

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 7, 2020, 3:57pm UTC](https://discourse.julialang.org/t/convert-lightxml-array-to-xmlelement/46163/3 "2020-09-07T15:57:16Z")

</div>

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:

```julia
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:

```julia
<Elements>
  <a/>
  <a/>
</Elements>

```

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [September 7, 2020, 6:05pm UTC](https://discourse.julialang.org/t/convert-lightxml-array-to-xmlelement/46163/4 "2020-09-07T18:05:36Z")

</div>

I see, I suppose my approach was wrong. I have followed the example and done the way you propose.

Kind regards
