• Post Reply Bookmark Topic Watch Topic
  • New Topic

XML Help  RSS feed

 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am building a synchronization solution for an app that has a local Access database and is not connected to the web or enterprise app when it collects data. I need to get data from the local app to the enterpise app and from the ent app to the local app twice each day when the user connects to the internet.

I have successfully built all of the XML docs that I need to use. They will be generated twice a day as well (one for incoming and one for outgoing). Building XML with Java was so simple I could not believe it. But, I am having a challenge with using the XML docs now that they are built.

I am not sure how I go about reading these docs in the code and then inserting the multiple rows of data into the respective database. Following is an example of the local XML doc build:

<?xml version="1.0" encoding="UTF-8" ?>
- <AssetOutXML>
<AssetID>5222935</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>4</AssetTypeID>
<Code>1</Code>
<Serial>1</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-13 20:58:49</addDate>
<AssetID>422627</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>422700</AssetTypeID>
<Code>111</Code>
<Serial>111</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-14 09:27:27</addDate>
<AssetID>3439544</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>4</AssetTypeID>
<Code>125</Code>
<Serial>125</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-14 09:48:37</addDate>
<AssetID>50138776319978073038569312956746906</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>3393406</AssetTypeID>
<Code>956</Code>
<Serial>956</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-15 16:19:17</addDate>
<AssetID>1096443</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>2121589</AssetTypeID>
<Code>155</Code>
<Serial>155</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-14 09:53:22</addDate>
<AssetID>1982671</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>4</AssetTypeID>
<Code>133</Code>
<Serial>133</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-14 10:04:17</addDate>
<AssetID>6</AssetID>
<CompanyID>1</CompanyID>
<AssetTypeID>6</AssetTypeID>
<Code>122</Code>
<Serial>122</Serial>
<Active>1</Active>
<addUserID>1</addUserID>
<addDate>2005-06-14 19:28:53</addDate>
<RecordCount>7</RecordCount>
</AssetOutXML>

Now, what do I do to read this XML doc and insert all the records into their respective rows?

If reading is nearly as simple as creating was, this has to be very easy. The tutorials and samples I read all show parsing an entire XML doc and priting it to the consol. I need to read a record and then put that record in the DB and then read the next one and so on (I suppose using SAX)? Do I need to assign each item to a variable or can I just create a resultset which will just insert records as they come in? Can someone give me an example and/or point me to a resource that gives an example along these lines?

Thanks so much,
Al
 
anupa oru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think there are couple of options for reading XML and inserting data into database
1.Using parsers: SAX or DOM,but these are little bit complicated to use if you don't have any idea about structure,moreover since you are exchanging data twice for each user it's important to consider performance issues also.These are little bit complicated to write but not impossible. Once you parse required elements,attributes you can use JDBC Api to insert that data into database.
2.Using JAXB: this is simple of exchanging info from xml to Java Object and vice versa.Moreover it's not necessary to be familiar with XML structure.JAXB will automatically generate Java classes for XML Schema. So inorder to retrieve the data you just have to call appropriate method on appropriate class so reading XML data is as simple as calling methods. Once you get the required data you can use JDBC Api to insert into database.Moreover for single schema you needn't to regerate Java classes everytime.If use JAXB reading XML is as simple as writing XML doc.
So I believe that using JAXB is good compare to parsers with regard to performance issues and code complexity.
I hope this will be helpful. Let me know if you need any further information.
Correct me if I am wrong.
Thanks
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.

I should clarify that the XML docs that are generated are pushed to the recieving location and then handled off line. The reason that there are two synchs each day is to make sure that synchs only happen after all users have reported in (incoming can happen any time but outgoing only after all incoming has been completed). So, the local machine generates an XML doc through a synch button in the swing app. That in turn is uploaded to the enterprise server where all the XML data is then parsed and loaded into the main DB. Once all users have reported in, the enterprise system generates XML docs for each table which are in turn downloaded to the local systems and then parsed and put in the local Access DB. Some of these tables (and subsequently the XML docs generated) will be huge. Do you think that JAXB is the right approach in this configuration? I am currently reading up on JAXB and have downloaded jwsdb 1.5. It sounds pretty interesting and it looks like all I have to do to get the variables out of the doc is to say myVar = node.getVar(); (or some such thing).

Thanks for the help.
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That in turn is uploaded to the enterprise server where all the XML data is then parsed and loaded into the main DB. Once all users have reported in, the enterprise system generates XML docs for each table which are in turn downloaded to the local systems and then parsed and put in the local Access DB. Some of these tables (and subsequently the XML docs generated) will be huge


What you need is some way to bind Database to XML and vice versa.
Data binding frameworks like JAXB, XMLBeans (I personally prefer XMLBeans) bind java-objects to XML and viceversa. How are you going bind Java objects to data base.

Instead of using JDBC to do that why dont you try some thing like Hibernate
to directly persist and retrive XML. Though I have not done it personally why dont you look at this article on hibernate. It may help

Regards,
Rajagopal
 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I will review that article right away.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!