By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,426 Members | 3,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,426 IT Pros & Developers. It's quick & easy.

Re: XML<-> JSON conversion. What do you think?

P: n/a
Max <ad**@tiscali.itwrites:
These cases demonstrates the difference between JSON and XML.
Not really. It shows that a particularly nave 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 think
to use JSON to transmit simples data and XML for structured data.
Your choice. Neither is inherently better (although JSON is often
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.'
Aug 10 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Max
Lasse Reichstein Nielsen ha scritto:
Not really. It shows that a particularly nave implementation
of a conversion from XML to JSON doesn't work well.
Really, then most of implementations of conversion from XML to JSON are
nave!
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?
For JSON, "textual" is a value of "a" and then { a: "textual" }.
This convertion is your expansive implementation created to bypass the
JSON limitations...
In fact, to obtain the string "some" instead of (example) e["#text"],
you must use a blinded mode tag.content[1], while it is more correct to
log on with the real name of the object/tag, that is "e"!
>I think
to use JSON to transmit simples data and XML for structured data.

Your choice. Neither is inherently better (although JSON is often
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

Can you suggests to me a good XML-JSON converter?
Aug 10 '08 #2

P: n/a
Max wrote:
Lasse Reichstein Nielsen ha scritto:
>Not really. It shows that a particularly naïve implementation of a
conversion from XML to JSON doesn't work well.

Really, then most of implementations of conversion from XML to JSON are
naïve!
It would seem you are not exactly in a position to make a correct assessment.
>What if the conversion of <esome <a>textual</acontent </e>

was:

{"tag": "e", "content" : [ "some", {"tag": "a", "content": ["textual"]}
"content" ]}

What is the big difference then?

For JSON, "textual" is a value of "a"
Nonsense.
and then { a: "textual" }.
And if there was

{ a: "textual", b: "foo" }

you could not know which one came first.
This convertion is your expansive implementation created to bypass the
JSON limitations...
There are no limitations in JSON but those you make up here.
In fact, to obtain the string "some" instead of (example) e["#text"], you
must use a blinded mode tag.content[1],
Not necessarily. As the DOM provides getElementsByTagName(), a similar
method can be implemented to traverse the object created from parsing JSON.
while it is more correct to log on with the real name of the object/tag,
that is "e"!
You are mistaken. Text child nodes of the same level do not belong together
unless they are adjacent. Your approach would allow for one text child node
per element only.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Aug 10 '08 #3

P: n/a
Max
Thomas 'PointedEars' Lahn ha scritto:
Max wrote:
>Lasse Reichstein Nielsen ha scritto:
>>Not really. It shows that a particularly naïve implementation of a
conversion from XML to JSON doesn't work well.
Really, then most of implementations of conversion from XML to JSON are
naïve!

It would seem you are not exactly in a position to make a correct assessment.
Why? I'm talking about proper implementation of a XML2JSON converter.
I say that then most of converters are naïve because I find many
converters that make a simple conversion from JSON.
At the same json.org website there are examples of simple conversion
(http://www.json.org/example.html)!
I have raised doubts and asked a question:
"Can you suggests to me a good XML-JSON converter?"
I have not received any answer, but only chats.

Max
Aug 11 '08 #4

P: n/a
Max wrote:
Thomas 'PointedEars' Lahn ha scritto:
>Max wrote:
>>Lasse Reichstein Nielsen ha scritto:
Not really. It shows that a particularly naïve implementation of a
conversion from XML to JSON doesn't work well.
Really, then most of implementations of conversion from XML to JSON
are naïve!
It would seem you are not exactly in a position to make a correct
assessment.

Why? I'm talking about proper implementation of a XML2JSON converter. I
say that then most of converters are naïve because I find many converters
that make a simple conversion from JSON. At the same json.org website
there are examples of simple conversion
(http://www.json.org/example.html)! I have raised doubts and asked a
question: "Can you suggests to me a good XML-JSON converter?" I have not
received any answer, but only chats.
You have received several answers addressing your question while we have
been engaging in a technical discussion about what would make up a good
converter. Whether you like that or not is a different matter, and how to
use search engines is beyond the scope of this newsgroup.

<http://jibbering.com/faq/>
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 11 '08 #5

P: n/a
Max
Thomas 'PointedEars' Lahn ha scritto:
You have received several answers addressing your question while we have
been engaging in a technical discussion about what would make up a good
converter. Whether you like that or not is a different matter, and how to
use search engines is beyond the scope of this newsgroup.
Ok, i have received technical answers but also accusation of lack about
XML2JSON converters... The only practical help was posted by Douglas. I
was wondering just that. Everything else is chats.

Max
Aug 11 '08 #6

P: n/a
Max wrote:
Thomas 'PointedEars' Lahn ha scritto:
>You have received several answers addressing your question while we have
been engaging in a technical discussion about what would make up a good
converter. Whether you like that or not is a different matter, and how to
use search engines is beyond the scope of this newsgroup.

Ok, i have received technical answers but also accusation of lack about
XML2JSON converters... The only practical help was posted by Douglas. I
was wondering just that. Everything else is chats.
Ask for a refund.
Score adjusted

PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Aug 11 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.