XML Parsing and Database Activity

V

vasko ckorovski

Hi Folks,

I have a XML file supplied by one of our content providers, that i have
to parse and import into a database. Im kind of at a junior to medium
level experience in Java, but am having trouble deciding/choosing which
XML Parser to use for this strange document.

I need to be able to parse this file, and grab all the values in the
attributes for the particular "Product" and insert into the database, i
know how to do the database insert, but im unsure on which parser to
use, and how to use it to be able to grab each "Product Instance" or
have a "Product" object in a collection after parsing the XML file.

Anyway this is the XML File, does anybody have any suggestions, or
pointers, to code snippets and or tutorials that i can read to figure
out how to do this?

Cheers

<?xml version="1.0" encoding="UTF-8"?>
<ROOT FileCreationDate="2005-07-20 21:51:14">
<Product Name="lotto" DrawNumber="2503" DrawDate="20050716"
DataEntryTimeStamp="20050716203333" NumberOfBalls="6" NumberOfSups="2"
SupName="Supp" >
<Ball Number="1" Result="11" />
<Ball Number="2" Result="32" />
<Ball Number="3" Result="13" />
<Ball Number="4" Result="12" />
<Ball Number="5" Result="3" />
<Ball Number="6" Result="34" />
<Ball Number="7" Result="14" />
<Ball Number="8" Result="33" />
<Dividends Name="lotto" DrawNumber="2503" DrawDate="20050716"
DataEntryTimeStamp="20050717001011" NumberOfDivisions="5" Error="">
<Division Number="1" DivPool="3323391.55" DivAmt="664678.31"
DivNum="5" />
<Division Number="2" DivPool="848909.10" DivAmt="10352.55"
DivNum="82" />
<Division Number="3" DivPool="1571126.70" DivAmt="1347.45"
DivNum="1166" />
<Division Number="4" DivPool="2673475.20" DivAmt="39.15"
DivNum="68288" />
<Division Number="5" DivPool="4253364.75" DivAmt="25.05"
DivNum="169795" />
</Dividends>
</Product>
<Product Name="OZ Lotto" DrawNumber="596" DrawDate="20050719"
DataEntryTimeStamp="20050719202737" NumberOfBalls="6" NumberOfSups="2"
SupName="Supp" >
<Ball Number="1" Result="9" />
<Ball Number="2" Result="25" />
<Ball Number="3" Result="27" />
<Ball Number="4" Result="12" />
<Ball Number="5" Result="2" />
<Ball Number="6" Result="38" />
<Ball Number="7" Result="14" />
<Ball Number="8" Result="40" />
<Dividends Name="OZ Lotto" DrawNumber="596" DrawDate="20050719"
DataEntryTimeStamp="20050719222318" NumberOfDivisions="5" Error="">
<Division Number="1" DivPool="1001540.24" DivAmt="0.00" DivNum="0" />
<Division Number="2" DivPool="150272.65" DivAmt="13661.15"
DivNum="11" />
<Division Number="3" DivPool="275498.85" DivAmt="2135.65"
DivNum="129" />
<Division Number="4" DivPool="475857.00" DivAmt="71.45"
DivNum="6660" />
<Division Number="5" DivPool="601379.10" DivAmt="42.30"
DivNum="14217" />
</Dividends>
</Product>
<Product Name="Powerball" DrawNumber="478" DrawDate="20050714"
DataEntryTimeStamp="20050714203143" NumberOfBalls="5" NumberOfSups="1"
SupName="Powerball" >
<Ball Number="1" Result="38" />
<Ball Number="2" Result="37" />
<Ball Number="3" Result="41" />
<Ball Number="4" Result="24" />
<Ball Number="5" Result="12" />
<Ball Number="6" Result="9" />
<Dividends Name="Powerball" DrawNumber="478" DrawDate="20050714"
DataEntryTimeStamp="20050714211249" NumberOfDivisions="7" Error="">
<Division Number="1" DivPool="3000000.00" DivAmt="3000000.00"
DivNum="1" />
<Division Number="2" DivPool="740022.25" DivAmt="67274.75"
DivNum="11" />
<Division Number="3" DivPool="338296.50" DivAmt="7517.70"
DivNum="45" />
<Division Number="4" DivPool="264338.40" DivAmt="132.70"
DivNum="1992" />
<Division Number="5" DivPool="148007.20" DivAmt="66.55"
DivNum="2224" />
<Division Number="6" DivPool="661032.05" DivAmt="23.45"
DivNum="28189" />
<Division Number="7" DivPool="1150607.30" DivAmt="12.70"
DivNum="90599" />
</Dividends>
</Product>
<Product Name="Wednesday lotto" DrawNumber="286" DrawDate="20050720"
DataEntryTimeStamp="20050720202620" NumberOfBalls="6" NumberOfSups="2"
SupName="Supp" >
<Ball Number="1" Result="4" />
<Ball Number="2" Result="7" />
<Ball Number="3" Result="2" />
<Ball Number="4" Result="17" />
<Ball Number="5" Result="38" />
<Ball Number="6" Result="23" />
<Ball Number="7" Result="14" />
<Ball Number="8" Result="28" />
<Dividends Name="Wednesday lotto" DrawNumber="286"
DrawDate="20050720" DataEntryTimeStamp="20050720215111"
NumberOfDivisions="5" Error="">
<Division Number="1" DivPool="270498.63" DivAmt="0.00" DivNum="0" />
<Division Number="2" DivPool="39193.20" DivAmt="4899.15"
DivNum="8" />
<Division Number="3" DivPool="70347.60" DivAmt="977.05"
DivNum="72" />
<Division Number="4" DivPool="115620.00" DivAmt="30.75"
DivNum="3760" />
<Division Number="5" DivPool="140587.20" DivAmt="14.40"
DivNum="9763" />
</Dividends>
</Product>
<Product Name="The Pools" DrawNumber="1042" DrawDate="20050716"
DataEntryTimeStamp="20050717170936" NumberOfBalls="6" NumberOfSups="1"
SupName="Supp" >
<Ball Number="1" Result="4" />
<Ball Number="2" Result="5" />
<Ball Number="3" Result="6" />
<Ball Number="4" Result="15" />
<Ball Number="5" Result="16" />
<Ball Number="6" Result="28" />
<Ball Number="7" Result="13" />
<Dividends Name="The Pools" DrawNumber="1042" DrawDate="20050716"
DataEntryTimeStamp="20050718175729" NumberOfDivisions="5" Error="">
<Division Number="1" DivPool="842102.91" DivAmt="842102.91"
DivNum="1" />
<Division Number="2" DivPool="3085.50" DivAmt="3085.50" DivNum="1" />
<Division Number="3" DivPool="9258.20" DivAmt="136.15" DivNum="68" />
<Division Number="4" DivPool="23180.40" DivAmt="14.10"
DivNum="1644" />
<Division Number="5" DivPool="18479.25" DivAmt="9.55"
DivNum="1935" />
</Dividends>
</Product>
<Product Name="Keno" DrawNumber="6052" DrawDate="20050720"
DataEntryTimeStamp="20050720185159" NumberOfBalls="20" NumberOfSups="0"
SupName="" >
<Ball Number="1" Result="1" />
<Ball Number="2" Result="3" />
<Ball Number="3" Result="4" />
<Ball Number="4" Result="8" />
<Ball Number="5" Result="13" />
<Ball Number="6" Result="14" />
<Ball Number="7" Result="15" />
<Ball Number="8" Result="21" />
<Ball Number="9" Result="26" />
<Ball Number="10" Result="37" />
<Ball Number="11" Result="46" />
<Ball Number="12" Result="54" />
<Ball Number="13" Result="55" />
<Ball Number="14" Result="56" />
<Ball Number="15" Result="59" />
<Ball Number="16" Result="66" />
<Ball Number="17" Result="69" />
<Ball Number="18" Result="72" />
<Ball Number="19" Result="74" />
<Ball Number="20" Result="78" />
<Dividends Name="Keno" DrawNumber="6052" DrawDate="20050720"
DataEntryTimeStamp="20050720185842" NumberOfDivisions="1" Error="">
<Division Number="1" Dollars="86187.00" Num="4922"
Jackpot="2000000.00" />
</Dividends>
</Product>
<Product Name="Super 66" DrawNumber="2503" DrawDate="20050716"
DataEntryTimeStamp="20050716203503" NumberOfBalls="6" NumberOfSups="0"
SupName="" >
<Ball Number="1" Result="0" />
<Ball Number="2" Result="6" />
<Ball Number="3" Result="5" />
<Ball Number="4" Result="2" />
<Ball Number="5" Result="2" />
<Ball Number="6" Result="2" />
<Dividends Name="Super 66" DrawNumber="2503" DrawDate="20050716"
DataEntryTimeStamp="20050717001536" NumberOfDivisions="5" Error="">
<Division Number="1" DivPool="64910.60" DivAmt="0.00" DivNum="0" />
<Division Number="2" DivPool="33330.00" DivAmt="6666.00"
DivNum="5" />
<Division Number="3" DivPool="25308.00" DivAmt="666.00"
DivNum="38" />
<Division Number="4" DivPool="31020.00" DivAmt="66.00"
DivNum="470" />
<Division Number="5" DivPool="30749.40" DivAmt="6.60"
DivNum="4659" />
</Dividends>
</Product>
<Product Name="Tatts 2" DrawNumber="7291" DrawDate="20050720"
DataEntryTimeStamp="20050720182109" NumberOfBalls="2" NumberOfSups="0"
SupName="" >
<Ball Number="1" Result="90" />
<Ball Number="2" Result="66" />
<Dividends Name="Tatts 2" DrawNumber="7291" DrawDate="20050720"
DataEntryTimeStamp="20050720184831" NumberOfDivisions="2" Error="">
<Division Number="1" DivPool="15444.00" DivAmt="1404.00"
DivNum="11" />
<Division Number="2" DivPool="10458.00" DivAmt="3.00"
DivNum="3486" />
</Dividends>
</Product>
</ROOT>
 
R

Raymond DeCampo

vasko said:
Hi Folks,

I have a XML file supplied by one of our content providers, that i have
to parse and import into a database. Im kind of at a junior to medium
level experience in Java, but am having trouble deciding/choosing which
XML Parser to use for this strange document.

I don't think you mean to ask which XML parser to use. From a client
perspective, all XML parsers in Java are (almost) the same.

Perhaps you mean to ask if you should use SAX or DOM? SAX provides a
callback type interface, where the parser informs you as it parses what
it has found. DOM creates an in memory object representing the entire
XML file.
I need to be able to parse this file, and grab all the values in the
attributes for the particular "Product" and insert into the database, i
know how to do the database insert, but im unsure on which parser to
use, and how to use it to be able to grab each "Product Instance" or
have a "Product" object in a collection after parsing the XML file.

Based on this paragraph, the SAX parser might be a little heavy for you,
because it requires more work. Look at the DOM interfaces, starting
with org.w3c.dom.Document (the javadoc is supplied with the JDK javadoc)
and see if that helps.
Anyway this is the XML File, does anybody have any suggestions, or
pointers, to code snippets and or tutorials that i can read to figure
out how to do this?

HTH,
Ray
 
R

Roedy Green

I need to be able to parse this file, and grab all the values in the
attributes for the particular "Product" and insert into the database, i
know how to do the database insert, but im unsure on which parser to
use, and how to use it to be able to grab each "Product Instance" or
have a "Product" object in a collection after parsing the XML file.


There are some XML-processing tools built into the JDK now, namely
JAXP 1.3.

See http://mindprod.com/jgloss/jaxp.html

check them out.

What is not clear to me is whether what comes with the JDK is
sufficient to write actual code, or if you need a plug-in
implementation, much the way you need one for Servlets.
 
M

mike hengins

Hi,
use XMLbeans, it's the best parser out there.

Ask me here if you want more details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top