These cases demonstrates the difference between JSON and XML.Not really. It shows that a particularly naïve implementation
of a conversion from XML to JSON doesn't work well.
What if the conversion of
<e>
some
<a>textual</a>
content
</e>
was:
{"tag": "e",
"content" : [ "some",
{"tag": "a", "content": ["textual"]}
"content" ]}
What is the big difference then?
I thinkYour choice. Neither is inherently better (although JSON is often
to use JSON to transmit simples data and XML for structured data.
shorter), but their performances depend on the choice of encoding
as much as the format of the data.
XML only has raw text and elements nodes. Element nodes both work as a
list of XML nodes and as a map from strings to strings (attributes),
and it has a type itself (the tag name). Everything is rolled into
this one compound construct.
JSON has two types of compound structures: (unordered) Maps and
(ordered) Lists (i.e., indexed by either name or by number).
In that sense, JSON is richer than XML, where name-indexed attributes
can only contain simple text.
I find that most data can be well represented in JSON, but starting
with XML data obviously makes JSON look worse than XML. Just as starting
with JSON data would probably make XML look worse.
/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'