XML<-> JSON conversion. What do you think?
- From: Max <adsl@xxxxxxxxxx>
- Date: Sat, 09 Aug 2008 15:19:46 +0200
According to Stefan Goessner, to obtain a correct conversion from XML to JSON it must apply some patterns to maintain order and structure of the elements. This not only serves to ensure a reversible conversion, but especially for documents such as SVG and SMIL that they require a precisely correct order of the elements.
For example, in the case of:
<e>
some
<a>textual</a>
content
</e>
a direct conversion would be:
"e": {
"#text": ["some", "content"],
"a": "textual"
}
that it would not make sense because it concatenates a text in an array ...
According to Stefan should be as follows:
"e": "some <a>textual</a> content"
In practice the central node should be included in the text.
The same goes for examples like this:
<a>x<c/>y</a>
{
"a":"x<c/>y"
}
Or with a CDATA:
<e>
some text
<![CDATA[ .. some data .. ]]>
more text
</e>
{
"e":"\n some text\n <![CDATA[ .. some data .. ]]>\n more text\n"
}
Or with a double CDATA:
<e>
<![CDATA[ .. some data .. ]]>
<![CDATA[ .. more data .. ]]>
</e>
{
"e":"<![CDATA[ .. some data .. ]]><![CDATA[ .. more data .. ]]>"
}
(I did not understand this last conversion...)
In any case, these examples are confined to CDATA, but in fact they may well extend to Processing Instruction, Comment etc
Indeed, this approach raises a serious question on the difference between JSON and XML.
Is it a correct approach or does the nodes need to convert in objects and chained arrays normally?
What do you think?
Max
.
- Follow-Ups:
- Re: XML<-> JSON conversion. What do you think?
- From: lorlarz
- Re: XML<-> JSON conversion. What do you think?
- From: Douglas Crockford
- Re: XML<-> JSON conversion. What do you think?
- From: Lasse Reichstein Nielsen
- Re: XML<-> JSON conversion. What do you think?
- From: Thomas 'PointedEars' Lahn
- Re: XML<-> JSON conversion. What do you think?
- Prev by Date: Re: Load xml in Javascript doesnt work in firefox
- Next by Date: Re: getElementById in MSIE
- Previous by thread: getElementById in MSIE
- Next by thread: Re: XML<-> JSON conversion. What do you think?
- Index(es):
Relevant Pages
|