Generate an XML file per row. Root and row tag problems

One Star

Generate an XML file per row. Root and row tag problems

I will ask for something that I have seen a few times in the forums but no "optimal" answer was given.
The scenario is well known, you a have a collection of rows which you want to output as DIFFERENT XML files, one for each row. And you want those xml files to be like this:
<row>
<col1></col1>
...
<colN></colN
</row>
You have tAdvancedFileOutputXML or tFileOutputXML for that. And you can see a nice option in them: "Split output in several files". You think that could be the answer to your problem, but not exactly... You will get something like this:
file1.xml //Oh, no. WRONG. I didnt put any root tag, but here it is...
----------
<root> //BAD
<row>
<col1></col1>
...
<colN></colN
</row>
// No root tag ended, bad XML...
file2.xml //This is perfect, what you want...
----------
<row>
<col1></col1>
...
<colN></colN
</row>
fileN.xml // This is the last file. If the first one is wrong, this also would be. It should have an </root> at the end, but no. This file is nice. But sure is a bug...
----------
<row>
<col1></col1>
...
<colN></colN
</row>

Because a "Row tag" is mandatory, you put your name for the row tag (in the example is "row"). The the root tag in the component (tFileOutputXML) is not mandatory, nice, because I don't want root tag, my row tags are root in each XML. But I read somewhere that they put a "root" tag if you don't create one. A safety net to avoid bad formed XML. But in this scenario that creates a first BAD formed XML and the rest are ok.
The suggested solution for this scenario is to use a tFlowToIterate and tGenerateRow for each row to create an XML. It's not bad idea, but it gets TOO HARD and long to code it if your row has 50+ columns, and have to do the same for other tables. Because you have to hand code every column in the tGenerateRow...
Well, a faster solution would be to choose if you want a default "root" tag or not. Let the users decide if they want to have well formed XML or not... If they want some strange structure in theirs XML files, let them...
I dont need something too strange, just the XML files I said in first place, and it is tiring to code every column in a tGenerateRow to achieve it...
Now I'm trying to erase the unwanted <root> tag from the first file of the "easy" solution.... any help in that?
PS: I also use this to generate file names: "C:/out-"+(String)globalMap.get("out.Name")+".xml" . And always get NULL...

Please, any help or enlighten will be appreciated,
cheers
Alex
One Star

Re: Generate an XML file per row. Root and row tag problems

hello,
I've got the same problem, waiting for an answer.
http://www.talendforge.org/forum/viewtopic.php?id=12493