Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a simple job that translates rows in an Excel spreadsheet to XML files (one file for each row):
-----------------------------------
File Excel —- row1 ——> tXMLMap —— outXML ——> tFileOutputXML
-----------------------------------
This works well. The challenge is that I need the XML files produced by tFileOutputXML to be named according to the value in one of the columns from the Excel spreadsheet: row1.DORIGINALFILENAME.
I believe I am missing something simple. row1.DORIGINALFILENAME is mapped to an XML element in the tXMLMap. It appears correctly in the XML output. I’m guessing that there is a way to refer to it in the “File Name” expression on the “Basic settings” tab of tFileOutputXML. I have tried:
————————————————————————
"/Users/bob/Documents/Poc/SampleData/ETL-Output/"+ row1.DORIGINALFILENAME
————————————————————————
This produces a set of XML output files named: null0, null1, null2,….
I have tried other expression for the “File Name”. None have worked. Is there another method for inserting the value of an XML element in the “File Name” expression within the tFileOutputXML?
Thanks,
Bob
====================================================
P.S. I have looked for a solution in previous posts to this forum. It appears this is a common pattern. There are OLD post on this forum that define the same issue:
1) From 2010: https://community.talend.com/t5/Design-and-Development/spliting-files-an-renaming-files/td-p/72252
The recommended solution here is:
————————————————
Hello
tMysqlInput---row1-->tFlowToIterate---iterate-->tAdvancedOutputXML
on tFlowToIterate, generate each row.
set the file as:
"..."+row1.id+".xml"
————————————————
2) From 2010: https://community.talend.com/t5/Design-and-Development/Generate-an-XML-file-per-row-Root-and-row-tag...
“PS: I also use this to generate file names: "C:/out-"+(String)globalMap.get("out.Name")+".xml" . And always get NULL…”
This thread does not have a recommended solution.
TRF,
Your instructions are clear and concise. I believe I followed them correctly. I am now getting the error:
---------------------
org.talend.designer.runprocess.ProcessorException: Job compile errors
At least job "MITRE_ETL_JOB" has a compile errors, please fix and export again.
Error Line: 3173
Detail Message: The method set(String, String) is undefined for the type Map<String,Object>
--------------------
If I comment out the line added to tJavaRow, the error is resolved:
------------------
//globalMap.set("xmlFilename", input_row.DORIGINALFILENAME);
-----------------
Your help is greatly appreciated,
Bob
I changed the globalMap.set() to globalMap.put() according to https://community.talend.com/t5/Archive/global-variables-in-java/td-p/96011 forum thread. Now the code runs without error, but I am still getting "null" for the file name when I use the following expression in fFileOutputXML for the "File Name":
-----------
"/Users/bob/Documents/Poc/SampleData/ETL-Output/"+ ((String)globalMap.get("xmlFilename"))+".xml"
-----------
Thanks,
Bob
If I print the globalMap entry immediately after setting it, then I see the value is set correctly:
-----------
globalMap.put("xmlFilename", input_row.DORIGINALNAME);
System.out.println((String)globalMap.get("xmlFilename"));
-----------
Prints the correct file name. Something must be happening to the map between the tJavaRow and tFileOutputXML components:
FileExcel ---- row1 ---> tJavaRow --- row 2 ---> tXMLMap --- outXML ---> tFileOutputXML
See attached screenshots for tFileOutputXML settings. The "File Name" is truncated. The full expression is:
------------
"/Users/bob/Documents/Innovators/Poc/SampleData/ETL-Output/"+ ((String)globalMap.get("xmlFilename"))+".xml"
------------
Thanks!,
Bob
Strange!
Does it come from the option "Split output on several files"?
@TRF Does it come from the option "Split output on several files"?
No. I disabled that and I still get a null value in the output filename from tFileOutputXML. I'm probably doing something stupid.