An json object with the name extracted from the root element (resultado) of the XML file, and n arrays of objects (row).
When I convert the some xml with Json-lib I get:
[
{"DESTAQUE":"0","NIVEL":"0","HX":"1","IMAGEM_MOUSEOVER":"0","NOME":"1ªPágina","ACTIVO":[],"TARGET":[],"SEC_ID_PAI":"194","CLASSE":"nav1","URL":"/","IMAGEM_PRINCIPAL":"0","ID_PAI":"81-1","ID":"81-1","ORDEM":"1"},
{"DESTAQUE":"0","NIVEL":"0","HX":"1","IMAGEM_MOUSEOVER":"0","NOME":"1ªPágina","ACTIVO":[],"TARGET":[],"SEC_ID_PAI":"194","CLASSE":"nav1","URL":"/","IMAGEM_PRINCIPAL":"0","ID_PAI":"81-1","ID":"81-1","ORDEM":"1"}
]
A simple json array.
This is the default pattern for the conversion XMLtoJson in json-lib?
If I want the previous format, I have to parse my self the conversion?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Fernando, can you please tell us what version of the library are you using in your tests?
The output may be an oversimplification of the xml as what you really have is an array named RESULTADO with two elements, each named ROW. (Arrays in json do not support names associated to elements, that would be a json object) XMLSerializer may return a top level json object or json array, other libraries will always give you a top level json object, even if the xml is really a representation of an array. I think it would be a good idea to add a configuration flag to XMLSerializer to always return a top level json object, which in this case would be what you expect.
Cheers,
Andres
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Andres for your prompt response.
I did the tests with the 2.2 version of json-lib.
And yes, I try to find something in the lib that can give me some control in the conversation. I thought that the option to give a name to the array would do the trick... I think it will be a nice improvement to XMLSerializer to have an option to choose the format.
By the way, I download and compiled the org.json source and with that lib I have the format I want. Exactly the some with the other javascript lib I mentioned in the previous post. And solve my problem.
If you want more details...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
I am trying to transform a simple xml with this format:
<?xml version="1.0" encoding="UTF-8"?>
<RESULTADO>
<ROW>
<ID>81-1</ID>
<NOME>1ªPágina</NOME>
<URL>/</URL>
<NIVEL>0</NIVEL>
<DESTAQUE>0</DESTAQUE>
<ORDEM>1</ORDEM>
<HX>1</HX>
<CLASSE>nav1</CLASSE>
<IMAGEM_PRINCIPAL>0</IMAGEM_PRINCIPAL>
<IMAGEM_MOUSEOVER>0</IMAGEM_MOUSEOVER>
<SEC_ID_PAI>194</SEC_ID_PAI>
<TARGET/>
<ACTIVO/>
<ID_PAI>81-1</ID_PAI>
</ROW>
<ROW>
<ID>81-1</ID>
<NOME>1ªPágina</NOME>
<URL>/</URL>
<NIVEL>0</NIVEL>
<DESTAQUE>0</DESTAQUE>
<ORDEM>1</ORDEM>
<HX>1</HX>
<CLASSE>nav1</CLASSE>
<IMAGEM_PRINCIPAL>0</IMAGEM_PRINCIPAL>
<IMAGEM_MOUSEOVER>0</IMAGEM_MOUSEOVER>
<SEC_ID_PAI>194</SEC_ID_PAI>
<TARGET/>
<ACTIVO/>
<ID_PAI>81-1</ID_PAI>
</ROW>
</RESULTADO>
When I put it in the Thomas Frank http://www.thomasfrank.se/xml_to_json.html javascript conversor I get exactly what I want:
{
resultado:{
row:[
{
id:'81-1',
nome:'1ªPágina',
url:'/',
nivel:0,
destaque:0,
ordem:1,
hx:1,
classe:'nav1',
imagem_principal:0,
imagem_mouseover:0,
sec_id_pai:194,
target:{
},
activo:{
},
id_pai:'81-1'
},
{
id:'81-1',
nome:'1ªPágina',
url:'/',
nivel:0,
destaque:0,
ordem:1,
hx:1,
classe:'nav1',
imagem_principal:0,
imagem_mouseover:0,
sec_id_pai:194,
target:{
},
activo:{
},
id_pai:'81-1'
}
]
}
}
An json object with the name extracted from the root element (resultado) of the XML file, and n arrays of objects (row).
When I convert the some xml with Json-lib I get:
[
{"DESTAQUE":"0","NIVEL":"0","HX":"1","IMAGEM_MOUSEOVER":"0","NOME":"1ªPágina","ACTIVO":[],"TARGET":[],"SEC_ID_PAI":"194","CLASSE":"nav1","URL":"/","IMAGEM_PRINCIPAL":"0","ID_PAI":"81-1","ID":"81-1","ORDEM":"1"},
{"DESTAQUE":"0","NIVEL":"0","HX":"1","IMAGEM_MOUSEOVER":"0","NOME":"1ªPágina","ACTIVO":[],"TARGET":[],"SEC_ID_PAI":"194","CLASSE":"nav1","URL":"/","IMAGEM_PRINCIPAL":"0","ID_PAI":"81-1","ID":"81-1","ORDEM":"1"}
]
A simple json array.
This is the default pattern for the conversion XMLtoJson in json-lib?
If I want the previous format, I have to parse my self the conversion?
Thanks.
Fernando, can you please tell us what version of the library are you using in your tests?
The output may be an oversimplification of the xml as what you really have is an array named RESULTADO with two elements, each named ROW. (Arrays in json do not support names associated to elements, that would be a json object) XMLSerializer may return a top level json object or json array, other libraries will always give you a top level json object, even if the xml is really a representation of an array. I think it would be a good idea to add a configuration flag to XMLSerializer to always return a top level json object, which in this case would be what you expect.
Cheers,
Andres
Thanks Andres for your prompt response.
I did the tests with the 2.2 version of json-lib.
And yes, I try to find something in the lib that can give me some control in the conversation. I thought that the option to give a name to the array would do the trick... I think it will be a nice improvement to XMLSerializer to have an option to choose the format.
By the way, I download and compiled the org.json source and with that lib I have the format I want. Exactly the some with the other javascript lib I mentioned in the previous post. And solve my problem.
If you want more details...