Khanderao on Emerging And Integration Technologies

Monday, March 05, 2007

Mapping between XML & JSON: Need a standard way

We need a standard way of mapping between XML and JSON. Let me explain why,

Currently, we have two popular types of mapping between XML and JSON.
1. Badgerfish http://badgerfish.ning.com
2. Mapping
The main difference between these two conventions is about namespace mapping.

For an example,

<xsl:root xsl="http://mynamespace.com">
<detail>my details </detail>
</xsl:root>


In case of “Badgerfish” the above xml would be mapped as:
{"xsl:root":{"@xmlns":{"xsl":"http://mynamespace.com"},"detail":{"$":"my details"}}}
In case of “Mapped”
In case of Mapped, namespace is allowed to map to a name e.g. http://mynamespace get mapped to mynamespace.root
{"mynamespace.root":{"detail":"my details"}}


While Badgerfish implements the full XML infoset in JSON, if there are many namespaces like following (example from Badgerfish site)

<alice xmlns="http://some-namespace" xmlns:charlie="http://some-other-namespace">
<bob>david</bob>
<charlie:edgar></charlie:edgar> <
/alice>
it becomes
{ "alice" : { "bob" : { "$" : "david" , "@xmlns" : {"charlie" : "http:\/\/some-other-namespace" , "$" : "http:\/\/some-namespace"} } , "charlie:edgar" : { "$" : "frank" , "@xmlns" : {"charlie":"http:\/\/some-other-namespace", "$" : "http:\/\/some-namespace"} }, "@xmlns" : { "charlie" : "http:\/\/some-other-namespace", "$" : "http:\/\/some-namespace"} } }
Which, in my opinion, seems to more cluttered than xml string.

In summary, due to two different ways of mapping, we need two parsers and builders for XMLß->JSON. This is very inconvenient. As a result we need a superset parser. Or we need a better and standardized mapping.


Labels:

Add to Technorati Favorites

Save This Page on del.icio.us

0 Comments:

Post a Comment

<< Home