Hi there!
I'm trying to write JSON from an existing XML document and got a problem with collecting all the elements with identical names. If my identical named elements are the only ones in the same depth in the XML document, the parser has no problem converting the document.
But if I have several siblings where a couple of them are identical, the result JSON is not transformed correctly.
I'm doing this from a Groovy script.:
import net.sf.json.xml.XMLSerializer
import net.sf.json.JSON
def xml = """<body>
<menulist>
<titles><foo>foo1</foo><foo>foo2</foo></titles>
<item>
<value><name>item1</name><action>doAction</action></value>
</item>
<item>
<value><name>item2</name><action>doAction</action></value>
</item>
</menulist>
</body>"""
XMLSerializer serializer = new XMLSerializer()
JSON json = serializer.read(xml)
return json.toString()
The JSON result:
[
{
"titles": [
"foo1",
"foo2"
],
"item": [
{
"name": "item1",
"action": "doAction"
},
[
{
"name": "item2",
"action": "doAction"
}
]
]
}
]
If I remove the <titles> node the XML document is correctly parsed.