Sep 02, 2016; 10:53
Jon Harris
[LP8.6] iterate function
Hi
I am working with a webservice - which is sending me XML data which we are importing to local database tables. Each record has around 70 fields, include a dozen "user defined" fields (the code below is a subset). We are still working on the data feed, so this is in a state of flux at the moment.
For debugging, I am using an iterate function to go through a map. The pertinent code is shown below.
var('xPathMap') = map(
'Stock_code' = '//STOCK_ITEM/STOCK_CODE/text()',
'Stock_desc' = '//STOCK_ITEM/STOCK_DESC/text()',
'userdefined1' = '//STOCK_ITEM/USER_DEFINED[1]/@NAME',
'userdefined2' = '//STOCK_ITEM/USER_DEFINED[2]/@NAME',
'userdefined3' = '//STOCK_ITEM/USER_DEFINED[3]/@NAME',
'uservalue1' = '//STOCK_ITEM/USER_DEFINED[1]/text()',
'uservalue2' = '//STOCK_ITEM/USER_DEFINED[2]/text()',
'uservalue3' = '//STOCK_ITEM/USER_DEFINED[3]/text()'
) ;
iterate( var('xPathMap') , var('thisPair') ) ;
var('thisField') = var('thisPair')->first ;
var('thisXpath') = var('thisPair')->second ;
var('thisValueArray') = XML_Extract(-XML=$theXML, -XPath=$thisXpath ) ;
var('thisValue') = var('thisValueArray')->get(1)->contents ;
var('thisField') ": " var('thisValue') '<br />' ;
/iterate ;
The technique works fine, however the issue is that the iterate function is "iterating" in a strange order, it's not the order I defined the map and it doesn't appear to be in the order of the values either. The result is my "userdefined" fields and their corresponding "uservalues" are appearing in apparently random places.
Can the iterate function use the "natural" order of the map, or do I have use a different technique. It's not as easy to maintain - but presumably, I could use two separate arrays, one for the xpath and one for my variables, and iterate/loop through that.
Thanks for any thoughts
Jon Harris
#############################################################
This message is sent to you because you are subscribed to
the mailing list Lasso Lasso@lists.lassosoft.com
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <Lasso-unsubscribe@lists.lassosoft.com>
Send administrative queries to <Lasso-request@lists.lassosoft.com>
Sep 02, 2016; 13:15
Jolle Carlestam
Re: [LP8.6] iterate function
Sep 02, 2016; 13:10
Jon Harris
RE: [LP8.6] iterate function
Sep 02, 2016; 15:35
Marc Vos
Re: [LP8.6] iterate function
Sep 02, 2016; 13:02
Steve Piercy - Website Builder
Re: [LP8.6] iterate function