AnsweredAssumed Answered

Create extra rows in CSV

Question asked by 83554003 on Mar 28, 2016
Latest reply on Mar 29, 2016 by 83554003

I'm trying to create a process to convert XML input to CSV output, but am having a problem with one of the requirements of my CSV output because I need to create an extra row for every group of data.

 

As an example, my input data has this format:

ProjectElement

     ProjectNumber

     ProjectName

     TaskElement

          TaskNumber

          TaskName

 

This is some example data to help make my desired output more clear:

<ProjectElement>
        <ProjectNumber>1111</ProjectNumber>
        <ProjectName>Project One</ProjectName>
        <TaskElement>
            <TaskNumber>1122</TaskNumber>
            <TaskName>Task One</TaskName>
        </TaskElement>
        <TaskElement>
            <TaskNumber>1133</TaskNumber>
            <TaskName>Task Two</TaskName>
        </TaskElement>
</ProjectElement>
<ProjectElement>
        <ProjectNumber>2222</ProjectNumber>
        <ProjectName>Project Two</ProjectName>
        <TaskElement>
            <TaskNumber>2233</TaskNumber>
            <TaskName>Task One</TaskName>
        </TaskElement>
        <TaskElement>
            <TaskNumber>2244</TaskNumber>
            <TaskName>Task Two</TaskName>
        </TaskElement>
</ProjectElement>

 

My output data must look like this:

NAME,PROJECTNUMBER,TASKNUMBER

Project One,1111,

Task One,1111,1122

Task Two,1111,1133

Project Two,2222,

Task One,2222,2233

Task Two,2222,2244

 

The NAME field would be the name of the element at the level being processed (ProjectName or TaskName), the PROJECTNUMBER field would reference parent project that the task is under and the TASKNUMBER field would obviously be the task number, or empty if providing the "header" for the project.

 

I have been able to use this input data in the past to create a CSV file combining project and task information on a single line, but adding the "header" line for each project has me baffled.  Is there a way to do this?  While I would prefer the order as I've shown in the example, it is not critical.  I would ok with having all of the Project numbers at the top of the document and the tasks at the bottom (or some other order if needed).

Outcomes