I have been reading lot of post on Stack Overflow and was wondering if I could really find the way how can I parse XML document and retrieve the data from it and insert it into my PostgreSQL database table which have exact column name as the XML schema tag have, but I failed to get the approx scenario. I have a following XML schema-
<?xml version="1.0">
<request uuid = 'xyz'>
<app hash='', name='', package = '', version='', filesize='',create_date='', upate_date=''>
<url>
<name>---</name>
<score>--</score>
</url>
<url>
<name>---</name>
<score>--</score>
</url>
</app>
</request>
and have two tables in PostgreSQL database name "app" and "url" shown below:
app
-----------------------------
appid(serial) | hash | name | package | version | filesize | create_date | update_date
and
url
--------------------
urlid(serial) | name | score
Note: urlid & appid are made as Primary Key in both the tables.
I needed to learn something that helps me insert the values inside these two tables with respect to their column ( example parse and insert) from the above given XML schema. I am using a PostgreSQL 9.2 version and I needed to do it using JAVA.
Anyone who could provide me a example of how should I parse the single XML document and have it inserted into two different tables would be really helpful.
Thank you in advance!
UPDATE
Do we suppose to use SAX parser here for parsing and insert likewise? Please help me understand the method to do this insertion.