M
Max
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
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