[json-lib-user] Problem collecting elements of identical name in a array
Brought to you by:
aalmiray
|
From: Rodolfo B. <ro...@id...> - 2009-09-21 09:18:15
|
Hi!
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.
Does anyone else have the same problem? Or maybe have a nice workaround?
--
Rodolfo Bunney <ro...@id...>
Systemutvikler @ http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
22 00 84 00
|