One Star

webservice output to an xml file

Hi,
I'm still fairly new to the use of Talend so apologies if this is a simple question but i'm still finding my way through all the components available in the studio.
I have a scenario where I need to
1) Retrieve ID's for users from a table in my database
2) Iterate through each ID and make a call to a webservice
3) Call the webservice method with the ID, and retrieve results
4) Output results for each ID into an XML file or some kind of output which can be manipulated further.
I have achieved the first 3 parts of this, the webservice retrieves the results for each ID, but at the moment all i can do with these is output them through the logrow component. I have attempted to output to an XML file, but this does not seem to let you append the xml file with the latest results, it just overwrites the contents, which as a result once the job is completed, leaves an xml file with just the last result of the iteration.
Does anyone have any suggestions, I have attached a screenshot of how the job currently runs.
Many thanks
Richard
8 REPLIES
One Star

Re: webservice output to an xml file

It's always the same problem when using an "iterate" link.
You have to create the file at the beginnint of the job :
tPrejob --onComponentOk--> tGenerateRow --Output--> tFileOutputXML
Then on the other component tFileOutputXML, check the "append" box.
This is the way I use, because it works exactly as if there was no "iterate" link in the process. Checking the "append" box on the existing component could be enough, but creating the file at the beginning of the job overwrites the file of the last execution, which is easier when developping.
One Star

Re: webservice output to an xml file

@nkxxDV: that's what I thought but I can't find the "append" check box in the tFileOutputXML component. Is there another way to do that?
Community Manager

Re: webservice output to an xml file

@brunogirin
The 'append' option is avaliable on tAdvancedFileOutputXML component. We generally use tAdvancedFileOutputXML instead of tFileOutputXML to output a xml file.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: webservice output to an xml file

@shong: when I use tAdvancedFileOutputXML, I get errors that says: "Loop element is missing" or "Require set as loop or set as group at least". I tried to add a loop element called "row" under the rootTag and then mapping all fields but it doesn't seem to resolve the error. I've attached a screenshot to show what I mean.
One Star

Re: webservice output to an xml file

Following the details from this other post, I changed the structure to include a group element. However, I still get the following exception on this component when I run my job:
Exception in component tAdvancedFileOutputXML_1
java.lang.Exception: can not find the file:/home/bruno/TOS-All-r31371-V3.2.1/workspace/out.xml
at filetransfer.filetransferjob_0_1.FileTransferJob.tFileList_1Process(FileTransferJob.java:2507)

Presumably, because I append to the file, it complains when the file doesn't exist. As I already have a tPrejob to clean up logs on startup, I tried to add a simple task to theat pre-job with a tFixedFlowInput and another tAdvancedFileOutputXML where the "append" option is not checked, in order to create the file's structure but that doesn't work either. Now, it only tells me that I have errors in both tAdvancedFileOutputXML but it doesn't give me any meaningful error message, nor are the errors listed in the "Problems" tab.
I attached a number of screen shots that show: what the overall job looks like and the XML tree configuration screen of both tAdvancedFileOutputXML.
Community Manager

Re: webservice output to an xml file

Hello
Exception in component tAdvancedFileOutputXML_1
java.lang.Exception: can not find the file:/home/bruno/TOS-All-r31371-V3.2.1/workspace/out.xml

As the exception message shows, the file doesn't exist, if you are checking 'append' option, the file must exist on your hard disk.
I tried to add a simple task to theat pre-job with a tFixedFlowInput and another tAdvancedFileOutputXML where the "append" option is not checked,

When you do a simple task for test, it is better to deactivate the second subjob.
About 'append the source xml file' feature, see 5975.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: webservice output to an xml file

@shong: thanks for your reply.
I had indeed worked out that I needed to create the XML file first before using the tAdvancedFileOutputXML task with the "append" option checked. I've now got the main job working by creating a skeleton XML file by hand prior to running the job but obviously having to manually create this skeleton file defeats the purpose of using a tool like Talend. Is there any way to include a task somewhere in order to do that? Topic #5975 that you mention doesn't say anything about it.
One Star

Re: webservice output to an xml file

Hi,

You can set the group element and loop element in TAdvancedFileOutputXML Component.

Please Find the attachment for the Settings i had configured.