Rick6334527
Posts: 0
Joined: Thu Oct 17, 2013 2:37 pm

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

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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

Hi Rick,

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

Rick6334527
Posts: 0
Joined: Thu Oct 17, 2013 2:37 pm

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

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

Rick6334527
Posts: 0
Joined: Thu Oct 17, 2013 2:37 pm

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

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

Hi Rick,

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

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.

Rick6334527
Posts: 0
Joined: Thu Oct 17, 2013 2:37 pm

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

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

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.

Return to “Issues”