Problem Statement: There is XML with 10k+ records. Need to convert into insert sql scripts.
Solution 1: XML –> XSD –> Java files –> Unmarshal XML
Step 1: Use XML Spy or Online tool to generate XSD for given XML.
Step 2: Generate Java code for xsd
Option 1: Use Eclipse plugin. This is plugin is very old.
Use JAXB plugin to generate java code for given XSD.
This is very old plug in and not working with latest stuff…Even it works with older version, I dont want to use it.
Option 2: This is also not good idea. Because it works only with 1.5
Step 1: Download JAXB. It is part of JWSD. http://java.sun.com/webservices/downloads/previous/webservicespack.jsp
Step 2: Go to jaxbbin location and try following commands
>xjc.bat -p com.package example_schema.xsd
Option 3: xjc.exe is part of Java 1.6 and available in /bin folder.
>xjc.exe -p com.package example_schema.xsd
Step 3: Read XML and Unmarshal using JAXB.
Step 4: Generate required output using java.
The above solution is time consuming and screwed up my time.
Solution 2: XML –> DOM Object –> Manipulate data
Using simple DOM solved the issue quickly. This is the best route, when xsd is not available.