Solved

Filling tables with XML data

Posted on 2004-04-24
21
301 Views
Last Modified: 2013-11-23
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
Comment
Question by:lina000
  • 9
  • 5
  • 4
  • +1
21 Comments
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
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
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
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
 
LVL 23

Expert Comment

by:rama_krishna580
Comment Utility
0
 

Author Comment

by:lina000
Comment Utility
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
 

Author Comment

by:lina000
Comment Utility
Just wondering if XPath might solve this problem!!
Does anyone know how can I use XPath in Java?
0
 
LVL 7

Accepted Solution

by:
maheshexp earned 500 total points
Comment Utility
0
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
the java implementation is available from v1.5
0
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
0
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
freely avaible XPath interface for java

http://jaxen.org/
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 23

Expert Comment

by:rama_krishna580
Comment Utility
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
>> 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
 

Author Comment

by:lina000
Comment Utility
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
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
It's a basic breadth-first tree traversal. Are you familiar with traversing hierarchical datastructures?
0
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
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
 

Author Comment

by:lina000
Comment Utility
traversing hierarchical datastructures??
I'm not familiar with that!! how can this help??
0
 
LVL 14

Expert Comment

by:Tommy Braas
Comment Utility
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
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
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
 

Author Comment

by:lina000
Comment Utility
I guess you are right!! the provided documents had somehow helped!!
0
 
LVL 7

Expert Comment

by:maheshexp
Comment Utility
thanks :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now