xmlbuilder2
xmlbuilder2 copied to clipboard
Cannot serialize arrays
Any time I try to convert an array to XML, I get Uncaught Error HierarchyRequestError: The operation would yield an incorrect node tree. Document already has a document element node.
To Reproduce
var a1 = [1, 2, 4];
var a2 = [{ p: "v" }, { p: "v" }];
var a3 = { a: [{ p: "v" }, { p: "v" }] };
var doc = create(a1).end();
Expected behavior To be able to serialize arrays and objects with arrays into xml. Make up elements if there isn't objects.
<items>
<item>1</item>
or
<array>
<item>
<p>v</p>
</item>
or
<a>
<p>v</p>
</a>
<a>
<p>v</p>
</a>
Version:
- node.js: 23.11
- xmlbuilder2 3.1.0
The same issue for serializing an object instance with multiple properties, such as { p1: "v", p2: "v" }. So it could be
<object>
<p1>v</p1>
<p2>v</p2>
</object>
Anything really other than throwing would be useful.