XMLWrite to multiple files

Post any question you may have in regards to GoAnywhere MFT and let our talented support staff and other users assist you.
If you need a quicker response, please create a support ticket via the customer portal my.goanywhere.com or contact our support team by email at [email protected].
2 posts Page 1 of 1

LPrendergast

Verified User
Posts: 14
Joined: Tue May 26, 2009 8:54 am

Post by LPrendergast » Thu Jan 25, 2018 2:44 pm
Hi, I have a recordset and want to write each record into its own XML file, the naming will based on the recordset ( I would use the first 4 fields of the recordset.).
My initial test names the file based on the first record but inserts each additional record into the same file instead creating separate files. If I take out the foreach loop (inside the XMLWrite) I get an error on compile. Is what I want possible? or should take totally different approach?

sample of my project below:
<project name="Item Master Create XML" mainModule="Main" version="2.0" logLevel="verbose">

<module name="Main">

<timestamp version="1.0" />


<sql label="Connect to DB" resourceId="XXXXXXX" version="1.0">
<query label="Retrieve Data" outputVariable="data">
. . . .
</query>
</sql>

<forEachLoop itemsVariable="${data}" currentItemVariable="record">

<xmlWrite label="Convert to XML" outputFile="/LTPLIB/ITEM_${record[2]}_${record[3]}_${record[1]}.xml" whenFileExists="overwrite" defaultTrim="right" defaultDateFormat="yyyy-MM-dd" defaultTimeFormat="HH:mm:ss" defaultTimestampFormat="yyyy-MM-dd HH:mm:ss.SSS" outputFileVariable="xmlFile" version="1.0">
<element name="ItemMaster" value="ItemMaster ">
<forEach inputRowSetVariable="${record}">
<element name="UPC_NUMBER" value="${record[1]}">
<element name="SEASON" value="${record[2]}" />
<element name="COMPANY" value="${record[3]}" />
<element name="DIVISION" value="${record[4]}" />
<element name="STYLE" value="${record[5]}" />
<element name="STYLEDISC" value="${record[6]}" />
<element name="LENGTH" value="${record[7]}" />
<element name="COLOR" value="${record[8]}" />
<element name="SIZE" value="${record[9]}" />
<element name="CATEGORY" value="${record[10]}" />
<element name="GROUP" value="${record[11]}" />
<element name="DELIVERY" value="${record[12]}" />
<element name="MSRP" value="${record[13]}" />
<element name="SELL" value="${record[14]}" />
<element name="ATTRIBUTE01" value="${record[15]}" />
<element name="ATTRIBUTE02" value="${record[16]}" />
<element name="ATTRIBUTE03" value="${record[17]}" />
<element name="ATTRIBUTE04" value="${record[18]}" />
<element name="ATTRIBUTE05" value="${record[19]}" />
<element name="ATTRIBUTE06" value="${record[20]}" />
<element name="ATTRIBUTE07" value="${record[21]}" />
<element name="ATTRIBUTE08" value="${record[22]}" />
<element name="ATTRIBUTE09" value="${record[23]}" />
<element name="ATTRIBUTE10" value="${record[24]}" />
<element name="ATTRIBUTE11" value="${record[25]}" />
<element name="ATTRIBUTE12" value="${record[26]}" />
<element name="ATTRIBUTE13" value="${record[27]}" />
<element name="ATTRIBUTE14" value="${record[28]}" />
<element name="ATTRIBUTE15" value="${record[29]}" />
</element>
</forEach>
</element>
<header><?xml version="1.0" encoding="UTF-8" ?></header>
</xmlWrite>

</forEachLoop>

<rename label="Backup File" inputFile="${CSVFile}" newName="ITEMMASTER_${system.currentDate}" whenFileExists="overwrite" version="1.0" disabled="true" />

</module>

</project>

Support_Jerrod

Support Specialist
Posts: 11
Joined: Wed Dec 13, 2017 5:52 pm

Post by Support_Jerrod » Thu Mar 15, 2018 8:47 pm
Hello Lloyd,

In this scenario, we recommend using the Print task instead of the Write XML task. Using the print task inside of a For-Each Loop will create a separate XML for each UPC number when the Append option is set to False in the advanced settings of the print task. In the print task, you will still reference the desired columns of your RowSet variable as you did in the Write XML task. You will then use the ${system.tab} variable to create the desired spacing in the output xml file. Below is a sample of how you will populate the text box of the Print task. I have also attached an example project using the Print task to write an XML file.

<?xml version="1.0" encoding="UTF-8" ?>
<ItemMaster>ItemMaster
${system.tab}<UPC_NUMBER>${record[1]}
${system.tab}${system.tab}<SEASON>${record[2]}</SEASON>
${system.tab}${system.tab}<COMPANY>${record[3]}</COMPANY>
${system.tab}${system.tab}<DIVISION>${record[4]}</DIVISION>
${system.tab}${system.tab}<STYLE>${record[5]}</STYLE>
${system.tab}${system.tab}<STYLEDISC>${record[6]}</STYLEDISC>
${system.tab}${system.tab}<LENGTH>${record[7]}</LENGTH>
${system.tab}${system.tab}<COLOR>${record[8]}</COLOR>
${system.tab}</UPC_NUMBER>

Thank you
Attachments
Create XML with print task.xml
Example Project
(1015 Bytes) Downloaded 763 times
Jerrod Foster
Support Analyst

e. [email protected]
p. 1.800.949.4696
w. HelpSystems.com
2 posts Page 1 of 1