import groovy.json.JsonSlurper; import groovy.xml.MarkupBuilder; import com.oracle.e1.common.OrchestrationAttributes; import java.text.SimpleDateFormat; HashMap < String, Object > main(OrchestrationAttributes orchAttr, HashMap inputMap) { HashMap < String, Object > returnMap = new HashMap < String, Object > (); returnMap.put("XMLComplete", "false"); def jsonIn = new JsonSlurper().parseText(inputMap.get("One Line Data")); def jsonData = jsonIn.fs_DATABROWSE_V0101B.data.gridData.rowset; if (jsonData.size() == 0) { returnMap.put("XMLComplete", "empty"); return returnMap; } def fileName = orchAttr.getTempFileName("oneLine.xml"); returnMap.put("XMLOutFileName", fileName); //class writer to write file def def sw = new StringWriter(); //builder xml def xml = new MarkupBuilder(sw); // create output file fileXmlOut = new File(fileName); def count = 0; // build the XML def an8Map = new ArrayList(); xml.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8"); xml.addressEntries() { for (int i = 0; i < jsonData.size(); i++) { def addressNumber = jsonData[i].F0101_AN8; if (an8Map.contains(addressNumber)) { continue; } an8Map.add(addressNumber); count++; xml.addressEntry(searchType: jsonData[i].F0101_AT1) { xml.addressNumber(addressNumber) xml.alphaName(jsonData[i].F0101_ALPH) xml.address() { xml.addressLine1(jsonData[i].F0116_ADD1) xml.city(jsonData[i].F0116_CTY1) xml.state(jsonData[i].F0116_ADDS) xml.zipCode(jsonData[i].F0116_ADDZ) xml.country(jsonData[i].F0116_CTR) } xml.phone() { xml.prefix(jsonData[i].F0115_AR1) xml.number(jsonData[i].F0115_PH1) } } } } //writing xml to file fileXmlOut.withWriter('UTF-8') { writer -> writer.write(sw.toString()) } orchAttr.writeDebug(sw.toString()); returnMap.put("xml", sw.toString()); returnMap.put("XMLComplete", "true"); returnMap.put("count", Integer.toString(count)); return returnMap; }