Write multi-level XML documents in GoAnywhere

Looking for an example project to get you started?
3 posts Page 1 of 1

Support_Steve

Support Specialist
Posts: 11
Joined: Fri May 08, 2009 8:59 am

Post by Support_Steve » Thu May 07, 2009 1:04 pm
This sample project demonstrates how to write a multi-level XML document from GoAnywhere. To setup this project in your environment please follow the steps defined in the following URL. Note: You will need the project XML that is attached to this post.

https://forum.goanywhere.com/viewtopic.php?f=21&t=87

Once you have the project loaded on your system you will need to download the Employee Address File and the Employee Data File attached to this post. Save them to the folder/library of your choice. You will need to update the project to point to these files if you are using a different path other than the one specified in the project. With the project loaded and modified to point the correct files you should be able to execute this project.

Project design overview:
In order to write an xml document, you need to have one or more RowSet variables created and available within the project. This means that there must be a Task before the XML Write Task that creates a RowSet output variable. The most common task that produces this variable type is the SQL task. You are querying data out of a database and storing the information in a RowSet variable. Other tasks that produce a RowSet variable are Read CSV, Read Fixed-Width, Read Excel, and Read XML.

The CSV Read Tasks that parse the EMP.csv and EMPADDR.csv files can easily be replaced by an SQL Task that queries the data from your database. The output variable created from the SQL Task is interchangeable with the variable created from the CSV Read Task, so long as the columns are equivalent.

Once you have the RowSet variable available, it’s time to build the document. On the top level of the XML Write task, the only required attribute is Output File. Specify where you want the xml file to be created. Another important attribute to look at is the When File Exists. GoAnywhere, by default, will automatically rename the output file if a file with the same name already exists. When running tests, it’s best to set this attribute to overwrite so you don’t have a directory full of:
file.txt
file 2.txt
file 3.txt
…etc

The rest of the attributes in the main task element have defaults that should be sufficient to create the xml document.

If you click on the Action menu, you have one main option, Element. This initial element, added to the xml document, is the document’s ROOT element. The Name attributes are the actual names of the tags that will be written to the document. We named our Root Element Employees.

When on the Root Element, click on the Action menu and you will see 4 main options: Element, Attribute, For-Each, and If

Under the root element we have a For-Each declared. A For-Each is required to loop through the rows in the RowSet. In the For-Each element, the required attribute is Input RowSet Variable. Here we tell that we will be looping through our ${empData} variable. So, for each row in the specified RowSet variable, we will write whatever is declared under this For-Each.

Once we have a For-Each, we can access data from the specified RowSet variable. Here we have declared an Employee element. This Employee element has an attribute called id.
<Employee id=”1001”>

</Employee>
So under the Employee element, we create an Attribute element with the name id. The value of this attribute is retrieved from the first column of the RowSet, so we set the value to ${empData[1]}. This is just like access data in an array.
Attachments
XMLWrite.xml
Project XML
(1.69 KiB) Downloaded 1982 times

EMPADDR.csv
Employee Address File
(331 Bytes) Downloaded 1462 times

EMP.csv
Employee Data File
(370 Bytes) Downloaded 1502 times

cmayil

Posts: 7
Joined: Thu Sep 08, 2016 8:43 am

Post by cmayil » Mon Sep 26, 2016 8:59 am
Hello Team,
I tried this example today but ended up with no data writing in the XML file though no errors reported by the System.

Finally found that, it wont generate/create/write XML file , if there is any blank value in the column. MGRNO value is blank in First row of the emp.csv file .
I had to substitute "0" for this null/blank value in the Data Option for this element. This worked for me.

cmayil

Posts: 7
Joined: Thu Sep 08, 2016 8:43 am

Post by cmayil » Mon Sep 26, 2016 10:06 am
Hello Team,
Please ignore my previous post. It seems that is no the issue.
I had open each file in excel then save & close , to get the correct formatted data. This was not explained in this article.
3 posts Page 1 of 1