XML to CSV like Excel

Mar 10, 2012 at 12:39 AM

Hello

I have a need to use something like how Excel converts an xml file into Table in Excel

repeating the parent data for the child nodes

and at the same time having different columns depending on the xpath path

and no mean to find how to develop that

any ideas ?

Coordinator
Mar 10, 2012 at 8:41 AM

Hi,

Could you refine your questions please as I am not totally clear what you mean? It sounds at first glance as something that is beyond the scope of XML to CSV conversion, though I understand how you ended up here. The XML converter works best with tabular data. Nested data (parent-child relationships) will only work under certain circumstances and final results, if any, may not be what you hoped for. You could download the source from this project as a starting point. I would also search stackoverflow.com for similar questions and in case you don't find anything relevant, post your question there. Again, try to make your question as clear as possible and include examples if feasible.

Regards, Tim

Mar 11, 2012 at 12:09 AM

thanks for your answer

here is an example

the input

<Document>
    <A attrA1="attrA1Val1" attrA2="attrA2Val1">
        <B attrB1="attrB1Val1" attrB2="attrB2Val1"/>
        <B attrB1="attrB1Val2" attrB2="attrB2Val2"/>
        <C attrC1="attrC1Val" attrC2="attrC2Val"/>
    </A>
    <A attrA1="attrA1Val2" attrA2="attrA2Val2">
        <B attrB1="attrB1Val3" attrB2="attrB2Val3"/>
        <D attrD1="attrD1Val" attrD2="attrD2Val"/>
        <E attrE1="attrE1Val" attrE2="attrE2Val"/>
    </A>
</Document>

here is the output

attrA1;attrA2;attrB1;attrB2;attrC1;attrC2;attrD1;attrD2;attrE1;attrE2
attrA1Val1;attrA2Val1;attrB1Val1;attrB2Val1;;;;;;
attrA1Val1;attrA2Val1;attrB1Val2;attrB2Val2;;;;;;
attrA1Val1;attrA2Val1;;;attrC1Val;attrC2Val;;;;
attrA1Val2;attrA2Val2;attrB1Val3;attrB2Val3;;;;;;
attrA1Val2;attrA2Val2;;;;;attrD1Val;attrD2Val;;
attrA1Val2;attrA2Val2;;;;;;;attrE1Val;attrE2Val

what it gives when opened with excel

attrA1 attrA2 attrB1 attrB2 attrC1 attrC2 attrD1 attrD2 attrE1 attrE2
attrA1Val1 attrA2Val1 attrB1Val1 attrB2Val1            
attrA1Val1 attrA2Val1 attrB1Val2 attrB2Val2            
attrA1Val1 attrA2Val1     attrC1Val attrC2Val        
attrA1Val2 attrA2Val2 attrB1Val3 attrB2Val3            
attrA1Val2 attrA2Val2         attrD1Val attrD2Val    
attrA1Val2 attrA2Val2             attrE1Val attrE2Val

the idea is that there are columns

and there are also the fact that the parent data is repeated for child nodes

and this is the way excel displays the content of an xml file

thanks Tim for your answer