• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

Filling tables with XML data

Hi!!
I need help with this!! I don't know the right way to implement such a problem!
Here is the scenario:
I do have a number of tables (relations) created in MS Access and I do have an XML document now what I'm looking for is to fill these tables with data from the XML document!

Here are the tables that I have (IDs are auto numbered fields)
Table Name: datee
   Fields:
      1- datee_ID
      2- datee_day
      3- datee_month
      4- datee_year
Table Name: paragraph
   Fields:
      1- paragraph_ID
      2- paragraph_String
Table Name: month
   Fields:
      1- month_ID
      2- month_String
Table Name: notee
   Fields:
      1- notee_ID
      2- notee_to
      3- notee_from
      4- notee_heading
      5- notee_datee_day
      6- notee_datee_month
      7- notee_datee_year
Table Name: year
   Fields:
      1- year_ID
      2- year_String
Table Name: day
   Fields:
      1- day_ID
      2- day_String
Table Name: to
   Fields:
      1- to_ID
      2- to_String
Table Name: from
   Fields:
      1- from_ID
      2- from_String
Table Name: heading
   Fields:
      1- heading_ID
      2- heading_String
Table Name: notee_paragraph
   Fields:
      1- notee_paragraph_ID
      2- notee_ParentID
      3- notee_paragraph_String

Here is the XML document
<notee>
    <to>Jane</to>
    <from>Tom</from>
    <heading>Reminder</heading>
    <paragraph>Hi</paragraph>
    <paragraph>Don’t be late!</paragraph>
    <datee>
        <day>13</day>
        <month>May</month>
        <year>2004</year>
    </datee>

   <to>Mark</to>
    <from>Ed</from>
    <heading>Invitation</heading>
    <paragraph>Hello</paragraph>
    <paragraph>Please come</paragraph>
    <paragraph>Take care</paragraph>
    <datee>
        <day>14</day>
        <month>March</month>
        <year>2004</year>
    </datee>

</notee>

Any help or advice will be highly appreciated!
0
lina000
Asked:
lina000
  • 9
  • 5
  • 4
  • +1
1 Solution
 
maheshexpCommented:
get a XML parser and make a database connectivity...
read teh data from XML and make a INSERT statements from the values....and update the information in the database
0
 
maheshexpCommented:
0
 
Tommy BraasCommented:
You should be able to use a SAX based parser with good results.  As of version 1.4 of the JDK there is a SAX parser included with the JDK. You can find the SAX parser and related classes here: http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/package-frame.html

A SAX parser is event based and will send events to registered listerners. Another option is to use the DOM model, in which the whole XML document is read into memory, parsed, and then made searchable. There is a DOM, or document arser available in the above package as well.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lina000Author Commented:
Thanks all for replying!
I used DOM class to parse the XML document but my only problem is in find an algorithm that I should follow to fill in these tables!! so HOW!! I'm a bit confused??
0
 
lina000Author Commented:
Just wondering if XPath might solve this problem!!
Does anyone know how can I use XPath in Java?
0
 
maheshexpCommented:
the java implementation is available from v1.5
0
 
maheshexpCommented:
freely avaible XPath interface for java

http://jaxen.org/
0
 
Tommy BraasCommented:
>> I used DOM class to parse the XML document but my only problem is in find an algorithm that I should follow to fill in these tables!! so HOW!! I'm a bit confused??
All you need to do now is walk the tree and add the data under the nodes to the respective tables in your database.

I don't think you would be served by using XPath as it is designed to point to an "address" in an XML document. You can certainly use it if you want.
0
 
lina000Author Commented:
Thanks all for replying!!
I guess my problem is with the logic it self (not the tools) I know using DOM or XPath will do it but the question is HOW can I implement such a thing!!
0
 
Tommy BraasCommented:
It's a basic breadth-first tree traversal. Are you familiar with traversing hierarchical datastructures?
0
 
maheshexpCommented:
u mean implement XPATH or DOM????

if i am right
here's a document to implement it

http://cafeconleche.org/books/xmljava/chapters/ch16.html
0
 
lina000Author Commented:
traversing hierarchical datastructures??
I'm not familiar with that!! how can this help??
0
 
Tommy BraasCommented:
Actually, lina000 used knowledge aquired from this Q to post another. The answers provided here have helped in the pursuit of solving the overall problem. I vote no refund.
0
 
maheshexpCommented:
lina000 got some documents for the references for XPATH, the answers provided here would solve her prolem somewhat....

i ubject to close this question
0
 
lina000Author Commented:
I guess you are right!! the provided documents had somehow helped!!
0
 
maheshexpCommented:
thanks :-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 9
  • 5
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now