Solved

Filling tables with XML data

Posted on 2004-04-24
21
302 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
ID: 10910845
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
ID: 10910851
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10910942
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
ID: 10911008
0
 

Author Comment

by:lina000
ID: 10911174
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
ID: 10911624
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
ID: 10912081
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10912097
the java implementation is available from v1.5
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10912128
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10912134
freely avaible XPath interface for java

http://jaxen.org/
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10912249
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10914973
>> 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
ID: 10918999
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
ID: 10919411
It's a basic breadth-first tree traversal. Are you familiar with traversing hierarchical datastructures?
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10919656
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
ID: 10922364
traversing hierarchical datastructures??
I'm not familiar with that!! how can this help??
0
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10965084
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
ID: 10965281
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
ID: 10986999
I guess you are right!! the provided documents had somehow helped!!
0
 
LVL 7

Expert Comment

by:maheshexp
ID: 10989396
thanks :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Printing to a specific printer tray (HP 806dn printer) 3 83
wordmultiple challenge 12 116
Eclipse Neon and jdk 1.8.0 11 122
map related example 6 24
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

943 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

10 Experts available now in Live!

Get 1:1 Help Now