I recommend using XQuery's element constructors. You can create elements dynamically using a computed element constructor:
element book {
attribute isbn {"isbn-0060229357" },
element title { "Harold and the Purple Crayon"},
element author {
element first { "Crockett" },
element last {"Johnson" }
}
}
results in
<book isbn="isbn-0060229357">
<title>Harold and the Purple Crayon</title>
<author>
<first>Crockett</first>
<last>Johnson</last>
</author>
</book>
(Example from the W3C XQuery specs)
In your case, you could use
element newTag { ... }