File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Parse XML using StaX insert into Hsql DB use maven built Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parse XML using StaX insert into Hsql DB use maven built" Watch "Parse XML using StaX insert into Hsql DB use maven built" New topic
Author

Parse XML using StaX insert into Hsql DB use maven built

Ray Lasher
Greenhorn

Joined: Mar 03, 2012
Posts: 4
Hi, I'm completely new to java and have to solve this problem. Will really appreciate if I can get any help regarding how I can divide this problem and in designing a blue print to solve it.

This is the XML file
<?xml version="1.0" encoding="UTF-8"?><ROOT DATE_CREATED="2011-09-15 13:33:45.804+0000" CREATED_BY="iMIS Collector" CLIENT_NAME="IDMSERVER" COMPANY_ID="13">
<Event Name="TXTDRV_TRACE"><Time>2011-09-15 11:03:45:834+0000</Time><Description><![CDATA[Test ERROR 1]]></Description></Event>
<Event Name="TXTDRV_TRACE"><Time>2011-09-15 13:53:45:834+0000</Time><Description><![CDATA[Test ERROR 2]]></Description></Event>
<Event Name="TXTDRV_TRACE"><Time>2011-09-15 14:13:45:834+0000</Time><Description><![CDATA[Test ERROR 3]]></Description></Event>
<Event Name="TXTDRV_TRACE"><Time>2011-09-15 15:35:45:834+0000</Time><Description><![CDATA[Test ERROR 4]]></Description></Event>
<Event Name="TXTDRV_TRACE"><Time>2011-09-15 17:34:45:834+0000</Time><Description><![CDATA[Test ERROR 5]]></Description></Event>
<Event Name="TXTDRV_TRACE"><Time>2011-09-15 19:38:45:834+0000</Time><Description><![CDATA[Test ERROR 6]]></Description></Event>
</ROOT>

I've to parse this, using StaX API and then Store it in HSQL DB. ( How do I parse it, what should be the rows and columns, no idea)

Then After storing this in DB. I've to

1) Calculate the max time stamp on the data. (Time is in GMT)
2) Figure out the difference between the max time and current time.
3) Replace the max time with current time (2011-09-15 19:38:45:834+0000 becomes current time)
4) Calculate the difference between the max time(before changing it) and the second max time and replace second max time by current time-difference (For example 2011-09-15 17:34:45:834+0000 becomes current time - 2hr 4 min
5) Repeat this till all the time slots are done.

We can have multiple XML files.

This has to be done using maven built (no idea what that is).

I use a Mac and I've maven installed in my system

Any Help will greatly be appreciated...


Currently I'm searching for algorithms on how to sort the date and change the times. If anyone can give me a blue print on how a fresher can approach this problem, I'll really appreciate it.

Thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38756
    
  23
Welcome to the Ranch
That question is too difficult for us here in “beginning”, so I shall move it.
Ray Lasher
Greenhorn

Joined: Mar 03, 2012
Posts: 4
oh Thanks Ritchie. Can you tell me where to move it please.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12779
    
    5
I've to parse this, using StaX API


Note that SAX and StaX parsing take a single pass through an XML document dealing with only one element at a time.

You would have to note the start of an Event, grab whatever data you want to store for that event, and make a database entry when you encounter the end of the event.

Since you are new to this sort of thing I recommend you look at Harold's free online book which includes plenty of examples.

Once you have the parsing mastered it will be time to consider the DB manipulations.

Bill
Ray Lasher
Greenhorn

Joined: Mar 03, 2012
Posts: 4
William Brogden wrote:
I've to parse this, using StaX API


Note that SAX and StaX ....

Bill



Hi Bill,

I"m able to parse the xml using StaX any idea how do I insert this parsed content into a hsql database using StaX itself?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12779
    
    5
StaX only knows about taking an XML document apart into a sequence of elements. It is a single purpose toolkit.


You might investigate the ServingXML toolkit which is said to provide for more complex operations, including parsing XML and inserting in a database. ServingXML is open source.

Bill


Ray Lasher
Greenhorn

Joined: Mar 03, 2012
Posts: 4
William Brogden wrote:StaX only knows about taking an XML document apart into a sequence of elements. It is a single purpose toolkit.






Thanks Bill,

I'll look into it.
Can you suggest me a way to implement the logic of changing dates after I parse them using StaX?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parse XML using StaX insert into Hsql DB use maven built