XML to Flat File or Database

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
>set JAVA_HOME=D:softwarejava_150_14
>set path=%JAVA_HOME%bin
>xjc.bat -p com.package example_schema.xsd

Option 3: xjc.exe is part of Java 1.6 and available in /bin folder.
>set JAVA_HOME=D:softwarejdk1.6.0_14
>set path=%JAVA_HOME%bin
>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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.