Page 1 of 2

Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 5:09 pm
by Rick6334527

I have a REST request that returns XML that contains some array data. I can map and display the array data to a list just fine if the example response has multiple items in the array so the array check box gets automatically checked. However if my sample response has only one item in the array the mapping fails even if I manually check the array check box. Is this a known issue? is there a work around?


Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 5:30 pm
by Kateryna Grynko

Hi Rick,

Could you please show us samples of the response when an only element is returned and when several elements.


Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 6:53 pm
by Rick6334527

Here is an example response. Value can be displayed in an arra list. But Alarm does not work. In the example there is one alarm but there could be many. Could the problem be that alarm does not have an explicit end tag?

code
<Response>
<DataItem name='value1' val='103' timestamp='Thu Sep 26 16:46:11 GMT 2013' &#47;>
<Device name='asset1' &#47;>
<History>
<Value tstamp='Thu Sep 26 11:54:30 GMT 2013'>63<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:32 GMT 2013'>5<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:34 GMT 2013'>81<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:36 GMT 2013'>49<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:38 GMT 2013'>39<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:40 GMT 2013'>62<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:44 GMT 2013'>81<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:46 GMT 2013'>39<&#47;Value>
<Value tstamp='Thu Sep 26 16:28:07 GMT 2013'>101<&#47;Value>
<Value tstamp='Thu Sep 26 16:45:52 GMT 2013'>103<&#47;Value>
<&#47;History>
<Loc lat='33&#46;00626837301169' lng='-96&#46;75809936453837' &#47;>
<Response>
<Alarm name='value1 is above recommended range&#46;' date='Thu Sep 26 16:46:11 GMT 2013' severity='1000' desc='' lat='33&#46;00626837301169' long='-96&#46;75809936453837' device='asset1' cond='Error' active='STARTED' &#47;>
<&#47;Response>
<&#47;Response>
/code


Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 7:10 pm
by Rick6334527

Here is an example with two alarms. This reply maps correctly

code
<Response>
<DataItem name='value1' val='103' timestamp='Thu Sep 26 16:46:11 GMT 2013' &#47;>
<Device name='asset1' &#47;>
<History>
<Value tstamp='Thu Sep 26 11:54:30 GMT 2013'>63<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:32 GMT 2013'>5<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:34 GMT 2013'>81<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:36 GMT 2013'>49<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:38 GMT 2013'>39<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:40 GMT 2013'>62<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:44 GMT 2013'>81<&#47;Value>
<Value tstamp='Thu Sep 26 11:54:46 GMT 2013'>39<&#47;Value>
<Value tstamp='Thu Sep 26 16:28:07 GMT 2013'>101<&#47;Value>
<Value tstamp='Thu Sep 26 16:45:52 GMT 2013'>103<&#47;Value>
<&#47;History>
<Loc lat='33&#46;00626837301169' lng='-96&#46;75809936453837' &#47;>
<Response>
<Alarm name='value1 is above recommended range&#46;' date='Thu Sep 26 16:46:11 GMT 2013' severity='1000' desc='' lat='33&#46;00626837301169' long='-96&#46;75809936453837' device='asset1' cond='Error' active='STARTED' &#47;>
<Alarm name='value1 is above recommended range&#46;' date='Thu Sep 26 16:46:11 GMT 2013' severity='1000' desc='' lat='33&#46;00626837301169' long='-96&#46;75809936453837' device='asset1' cond='Error' active='STARTED' &#47;>
<&#47;Response>
<&#47;Response>
/code


Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 7:40 pm
by Kateryna Grynko

Hi Rick,

Do you have an Alarm identified as "Array"? Could you please show us screenshots of your service mapping and Response parameters?


Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 7:45 pm
by Rick6334527

Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 7:46 pm
by Rick6334527

Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 8:56 pm
by Kateryna Grynko

Rick,

Mobilelistitem is not a container. Only container components can be multiplied by mapping. Add a Grid component to this Mobilelistitem, map array 'Alarm' to it. Then bring your labels to this grid, and set mapping to them as before.


Xml Array mapping not working when array has only one item.

Posted: Tue Oct 22, 2013 9:16 pm
by Rick6334527

Same issue. I did as you suggested and the multiple alarms show up fine. A single alarm does not show. I do not think you need the grid as the multiple alarms work fine with the list item. This issue is that when only one item comes in the reply it no longer thinks it is an array so the mapping fails.


Xml Array mapping not working when array has only one item.

Posted: Wed Oct 23, 2013 10:56 am
by Maryna Brodina

Hello! Sorry for misunderstanding. You don't need to use Grid. Please use List. List increases only if you map array, but if your xml is a one value then after parsing you won't get array. Here is a workaround:
1) If it's your service better do not return xml, but json (it's easier to see if it's an array)
2) Create Generic service to recieve data, parse, check if Alarm not array then make it array.