Page 1 of 1

Contents of a csv file

Posted: Thu Jun 05, 2014 7:46 pm
by Shoma_Costco
I need to get the contents of a csv file to be sent as one of the elements in a soap request to call a web service. When I use set variable to get contents (specifying file path), the data set in the variable is all junk values and not real data. Also my file is relatively large having customer related details. Could you please help with this requirement using Goanywhere.

Re: Contents of a csv file

Posted: Thu Jun 12, 2014 8:00 am
by Support_Jon
Shoma,

You should be able to set your variable to the file needed and include that as the value of your XML element as in this example.
Code: Select all
<project name="CSV in XML" mainModule="Main" version="2.0">

	<module name="Main">

		<setVariable label="set variable to file contents" name="contents" inputFile="/linoma/goanywhere/userdata/documents/user/sample.csv" version="2.0" />


		<print label="print file contents to job log" version="1.0">
			<![CDATA[-- begin file contents --
${contents}
-- end file contents --]]>
		</print>


		<xmlWrite label="write XML" outputFile="/linoma/goanywhere/userdata/documents/user/output.xml" version="1.0">
			<header><?xml version="1.0" encoding="UTF-8" ?></header>
			<element name="file" value="${contents}" />
		</xmlWrite>

	</module>

</project>

If you have issues with the appearance of the file contents, please verify the encoding of your input csv file. You may need to specify that on the set variable task and may also need to adjust the header of your XML to specify proper encoding as well.
Code: Select all
<setVariable label="set variable to file contents" name="contents" inputFile="/linoma/goanywhere/userdata/documents/user/sample.csv" encoding="utf-8" version="2.0" />
I hope this helps you out.

Thanks - Jon