JSFiddle - React, Tailwind, and code Playground
HTML
<xml>
<element>value</element>
<duplicate>dup1</duplicate>
<duplicate>dup2</duplicate>
</xml>
JavaScript
function parse(xml) {
var o = {};
$(xml).find('*').andSelf().contents().filter(function() {
return this.nodeType == 3 && $.trim(this.nodeValue);
}).each(function() {
var p = this.parentNode.nodeName;
if (!o[p]) o[p] = [];
o[p].push(this.nodeValue);
});
return o;
}
console.dir(parse($("xml").get(0)));