How can we convert XML file to CSV?

后端 未结 6 594
星月不相逢
星月不相逢 2021-01-29 09:05

I am having an XML file



    
        
        

        
6条回答
  •  Happy的楠姐
    2021-01-29 09:48

    Using XSLT is often a bad idea. Use Apache Commons Digester. It's fairly easy to use - here's a rough idea::

    Digester digester = new Digester();
    
    digester.addObjectCreate("Results/Row", MyRowHolder.class);
    digester.addCallMethod("Results/Row/COL1","addCol", 0);
    // Similarly for COL2, etc.
    digester.parse("mydata.xml");
    

    This will create a MyRowHolder instance (where this is a class you provide). This class would have a addCol() method which would be called for each with the contents of that tag.

提交回复
热议问题