I'm using xmlbuilder to generate an xml file dynamically from data in a query. For the retailerTypeId custom-attribute node I need to loop through an array of retailerTypeIds and add a value node for each one in the array.
Everything I do to inject a for loop to determine what values are needed for each new store node breaks the code. Right now I'm inserting the first one in a possible string of values separated by the semi-colon. I've tried everyway I can think of an can't get it to work. Can anyone help?
xml.att('xmlns', 'http://www.demandware.com/xml/impex/store/2007-04-30')
.ele('store', {'store-id': storeRecord.ID})
.ele('name', storeRecord.LOCATION_NAME__C).up()
.ele('custom-attributes')
.ele('custom-attribute', { 'attribute-id': 'retailerTypeId', 'xml:lang': 'x-default' })
.ele('value', storeRecord.RETAILER_TYPE__C.split(';')[0]).up()
.up()
.up()
.up()
xml.end({ pretty: true});`
I was attempting something like this but don't have the syntax correct as it closes the custom-attribute node:
.ele('custom-attribute', { 'attribute-id': 'retailerTypeId','xml:lang' : 'x-default' })
for (var i = 0; i < retailerTypes.length; i++) {
xml.ele('value').txt(retailerTypes[i])
.up()
}
.up()