문제

My objective is to create a single CSV file with the data from XML files. In a folder, I have multiple XML files. The number of XML files will vary based on a day. Should I combine all the XML files first and then create the CSV or create CSV for each and then combine?

An example in Java would be really helpful. I can post a sample of XML file if needed. All the XML files are the same format.

도움이 되었습니까?

해결책

I'd generate CSV per XML file first, then concatenate the CSV output; concatenating the Xml files would result in invalid XML unless you created a new root document element.

In "plain" java, you're essentially going to need to parse each XML document into memory and select which fields you want to output as CSV, and write that output code.

However, this is an ideal job for XSLT, which can be invoked either from Java or from an ant task. An XSL template in text mode can select values from the XML document and write them out as CSV.

This has been described here: XML to CSV Using XSLT

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top