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.
I added a tJavaRow AFTER the tFileOutputXML and the "xmlFilename" is successfully retrieved from the global map:
((String)globalMap.get("xmlFilename"))
So there must be some problem with accessing the globalMap within the "File Name" expression of tFileOutputXML!
I stumbled upon Rilhia Solutions tutorial here. Notice section 6: "Output to file (tFileOutputXML)". The default expression from generating the file name is:
context.fileoutputpath+((Integer)globalMap.get("tLoop_1_CURRENT_ITERATION")).intValue()+".xml";
Interesting! They are accessing the globalMap so it must be in scope correctly. There must be a bug in Talend when parsing a user provided expression for "File Name" in tFileOutputXML.
Meantime, I tried hacking in different forms of the expression (e.g. single and double escaping the quotes in my globalMap.get() call) to work around the issue. I was not able to guess an alternative form that would parse correctly. Perhaps someone has a suggestion?
Thanks,
Bob
Just for fun, I tried accessing the same variable Talend uses in the default file name expression:
((String)globalMap.get("tLoop_1_CURRENT_ITERATION"))
I get null for this as well.
I am using DI version 6.4.1
Bob
Hi,
Could you add a tFlowToIterate and tFixedFlowInput after your tXmlMap ? I tested it and it works fine:
Eric
Without tFlowToIterate, the file name of component tFileoutputXML is determined in the first step (Before your tJavaRow code is executed. You can see it setting a breakpoint at these two steps).