i would like to convert from CSV to XML with Java/Javascript.
For example my CSV file is like this table:
| ID | OLO |
| 12345 | TLC |
| 12345 | VPN |
| 67890 | TLC |
I would like to have an XML file like this:
<?xml version='1.0' encoding='UTF-8'?>
<Custom name="Custom_ListaOLO">
<Attributes>
<Map>
<entry key="12345">
<value>
<List>
<String>TLC</String>
<String>VPN</String>
</List>
</value>
</entry>
<entry key="67890">
<value>
<List>
<String>TLC</String>
</List>
</value>
</entry>
</Map>
</Attributes>
</Custom>
or:
<?xml version='1.0' encoding='UTF-8'?>
<Custom name="Custom_ListaOLO">
<Attributes>
<Map>
<entry key="12345">
<value>
<List>
<String>TLC</String>
<String>VPN</String>
</List>
</value>
</entry>
<entry key="67890", value="TLC />
</Map>
</Attributes>
</Custom>
Can you help me?
you can fulfill the above requirement using JAXB marshaling with the MOXy implementation.
JAXB Java Architecture for XML Binding (JAXB) is a software framework that provides way to map Java classes to XML representations. for more info
JAXB MARSHALING converting the java objects to xml. for more info
MOXy enable developers to handle the complex XML structures. for more info
firstly read the csv file and create java objects, then convert java objects to xml using jaxb marshaling with moxy implementation.
try with following solution,
create two java pojo classes (
CustomandEntry) for represented<Custom>and<entry>elements of xml file,Custom.java
Entry.java
read the csv file, create java objects and convert it to xml,
inputCSV.csv
output.xml