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



Thomas 'PointedEars' Lahn ha scritto:
Document of which type would not require a precisely correct order of the
elements?

Any custom XML document can not require a correct order of elements...

It would not. A direct conversion could be:

[
{
nodeName: "e",
attributes: {},
childNodes: [
{
nodeName: "#text",
nodeValue: "\n some\n "
},
{
nodeName: "a",
attributes: {},
childNodes: [
{"#text": "textual"}
]
},
{
nodeName: "#text",
nodeValue: "\n content\n"
}
]
}
]

A possibility...

that it would not make sense because it concatenates a text in an array ...

It is you who is not making sense here. "Concatenates a text in an array"?

According to Stefan should be as follows:

"e": "some <a>textual</a> content"

When a JSON converter find two or more #text nodes it create one array with all strings elements:

<e>
some
<a>textual</a>
content
</e>

->

"e": {
"#text": ["some", "content"],
"a": "textual"

}

I think that a JSON converter, in this case, can join strings:

"e": {
"#text": "some content",
"a": "textual"

}

What do you think?

A possibility, but it would involve deserializing the content afterwards.
It would be even more inefficient than to serve XML in the first place.

Yes, I agree with you. In this case, a use of JSON it would be wrong.
.



Relevant Pages

  • Re: Looping XML
    ... node that has some value it informs me "null" on NodeValue and the next ... loop the NodeName says: "#text" and shows me the correct value...? ... The technical explanation is that the text of a node is in fact a node ...
    (microsoft.public.vb.general.discussion)
  • Re: What is #text??
    ... >> For text nodes, the nodeName ... > nodeValue should be the text of that textnode. ...
    (microsoft.public.scripting.jscript)
  • Re: What is #text??
    ... Dave wrote: ... > For text nodes, the nodeName ... nodeValue should be the text of that textnode. ...
    (microsoft.public.scripting.jscript)