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



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
.



Relevant Pages

  • Re: XML<-> JSON conversion. What do you think?
    ... then most of implementations of conversion from XML to JSON are naïve! ...
    (comp.lang.javascript)
  • Re: XML<-> JSON conversion. What do you think?
    ... of a conversion from XML to JSON doesn't work well. ... to use JSON to transmit simples data and XML for structured data. ... XML only has raw text and elements nodes. ...
    (comp.lang.javascript)
  • Re: XML<-> JSON conversion. What do you think?
    ... then most of implementations of conversion from XML to JSON are ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Exult XML Conversion Wizard 1.2
    ... Easily convert XML to MS Access, CSV, HTML, XLS, Text and other ... Converting even complex XML files is a snap. ... interface which steps the user through the conversion. ...
    (comp.software.shareware.announce)
  • conversion from Quicksilver to XML with ITK
    ... I am concerned with a conversion project right now, ... interleaf documents into xml format. ... got my headings as microdocs in frames and when converting the files ... extracting the text which I used for my index: I got an index with 2 ...
    (comp.text.interleaf)