can anyone help me to write a java code for matching the xml elementdata with the my sql database

  • Thread starter er.yogeshkhandelwal
  • Start date
E

er.yogeshkhandelwal

Hi,

I'm having one XML and one mysql database..I am able to insert the xml
element data into the database.Now i want to retrive the data from
database table and want to match the data with the xml element data.I
have written the code for parsing XML and also written the code for
fetching the data from database but not getting how do i match both..

All idea would be really appreciated.

Thanks
 
R

RedGrittyBrick

Hi,

I'm having one XML and one mysql database..I am able to insert the xml
element data into the database.Now i want to retrive the data from
database table and want to match the data with the xml element data.I
have written the code for parsing XML and also written the code for
fetching the data from database but not getting how do i match both..

Er, canonicalize? and maybe then do a String compare?
http://www.w3.org/TR/2000/CR-xml-c14n-20001026
All idea would be really appreciated.

I'm having trouble working out what you are trying to do. Maybe you
could create a small example to illustrate what you mean? See
http://sscce.org.
 
E

er.yogeshkhandelwal

Er, canonicalize? and maybe then do a String compare?http://www.w3.org/TR/2000/CR-xml-c14n-20001026




I'm having trouble working out what you are trying to do. Maybe you
could create a small example to illustrate what you mean?  Seehttp://sscce.org.

--
RGB


Er, canonicalize? and maybe then do a String compare?http://www.w3.org/TR/2000/CR-xml-c14n-20001026




I'm having trouble working out what you are trying to do. Maybe you
could create a small example to illustrate what you mean? Seehttp://sscce.org.

I have attached my xml file and database columns name...and also
writing this program because i don't want any dependency on XSD..

<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/>
<football-cfb-schedule>
<game-schedule>
<visiting-team>
<team-name name="Eagles" alias="NCCent"/>
<team-city city="North Carolina Central"/>
<team-code id="6121" division="2"/>
<team-conference conference="Independents (FCS)" id="74" />
<ranking ranking="0" />
</visiting-team>
<home-team>
<team-name name="Golden Rams" alias="ALBAGA"/>
<team-city city="Albany State"/>
<team-code id="357" division="3"/>
<team-conference conference="Southern Intercollegiate Athletic"
id="37" />
<ranking ranking="0" />
</home-team>
<date year="2007" month="8" date="25" day="6"/>
<time hour="18" minute="00" timezone="Eastern"/>
<gamedate-day day="6" />
<tba tba="false" />
<week week="1"/>
<gamecode code="200708250357" global-id="764950"/>
<gametype type="Regular Season" />
<stadium name="Albany Municipal Coliseum" city="Albany" state="GA"
id="2081" />
<bowl id="" name="" />
<status status="Final"/>
<visiting-team-score score="10"/>
<home-team-score score="16"/>
<total-quarters total="4"/>
<outcome-visit outcome="Loss" conference-outcome="No game" />
<outcome-home outcome="Win" conference-outcome="No game" />
</game-schedule>

</football-cfb-schedule>
</sports-schedule>
</sports-statistics>
</cfb-schedule-document>






column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule
column name=VISIT_TEAM_NAME table=cfb_schedule
column name=VISIT_TEAM_ALIAS table=cfb_schedule
column name=VISIT_TEAM_CITY table=cfb_schedule
column name=VISIT_TEAM_CODE table=cfb_schedule
column name=VISIT_TEAM_CODE_GLOBAL_ID table=cfb_schedule
column name=VISIT_TEAM_DIVISION table=cfb_schedule
column name=VISIT_TEAM_CONFERENCE table=cfb_schedule
column name=VISIT_TEAM_CONF_ID table=cfb_schedule
column name=VISIT_TEAM_RANK table=cfb_schedule
column name=HOME_TEAM_NAME table=cfb_schedule
column name=HOME_TEAM_ALIAS table=cfb_schedule
column name=HOME_TEAM_CITY table=cfb_schedule
column name=HOME_TEAM_CODE table=cfb_schedule
column name=HOME_TEAM_CODE_GLOBAL_ID table=cfb_schedule
column name=HOME_TEAM_DIVISION table=cfb_schedule
column name=HOME_TEAM_CONFERENCE table=cfb_schedule
column name=HOME_TEAM_CONF_ID table=cfb_schedule
column name=HOME_TEAM_RANK table=cfb_schedule
column name=GAME_DATETIME table=cfb_schedule
column name=LOCAL_GAME_DATE table=cfb_schedule
column name=LOCAL_TIME table=cfb_schedule
column name=TBA table=cfb_schedule
column name=WEEK table=cfb_schedule
column name=GAME_CODE table=cfb_schedule
column name=GAME_GLOB_ID table=cfb_schedule
column name=GAME_TYPE table=cfb_schedule
column name=STADIUM_NAME table=cfb_schedule
column name=STADIUM_CITY table=cfb_schedule
column name=STADIUM_STATE table=cfb_schedule
column name=STADIUM_ID table=cfb_schedule
column name=STADIUM_GLOBAL_ID table=cfb_schedule
column name=BOWL_CODE table=cfb_schedule
column name=BOWL_NAME table=cfb_schedule
column name=GAMESTATE_STATUS table=cfb_schedule
column name=VISIT_TEAM_SCORE table=cfb_schedule
column name=HOME_TEAM_SCORE table=cfb_schedule
column name=TOTAL_QUARTERS table=cfb_schedule
column name=OUTCOME_VISIT table=cfb_schedule
column name=OUTCOME_VISIT_CONFERENCE table=cfb_schedule
column name=OUTCOME_HOME table=cfb_schedule
column name=OUTCOME_HOME_CONFERENCE table=cfb_schedule

I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component to finish this task but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..
 
R

RedGrittyBrick

I have attached my xml file and database columns name...

OK but that isn't an SSCCE as described at http://sscce.org.
and also
writing this program because i don't want any dependency on XSD..

You'll need a mapping from XML tags and attributes to the column-names
of your database table.

<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/> [...]


column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule [...]
I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component

I'm not familiar with JAXB but there are certainly DOM and SAX parsers
that don't require XSD.

to finish this task

Have you already finished this task?

but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..

Unless your XML tag and attribute names can be inferred from the column
names (or vice versa) - you can't write a truly generic program that
deals with any arbitrary XML and corresponding tables. Particularly as,
in your example, the XML isn't flat (you have <home-team><teamname> and
<visiting-team><team-name> corresponding to HOME_TEAM_NAME and
VISIT_TEAM_NAME respectively).

You could parse the XML using DOM, extract the elements that correspond
to the record key for the database table, lookup the record using JDBC,
Hibernate etc, then extract every element from the DOM document and
compare the values with those obtained by the database. The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

Is this what you want to do?

If so, which part are you having problems with?
 
M

Martin Gregorie

On Mon, 02 Feb 2009 05:52:48 -0800, er.yogeshkhandelwal wrote:

That's a terrible database design. It looks like something an Access
monkey might cobble together because he knows no better rather than a
properly thought out design. That table contains:
- disguised repeating data
- unrelated data items
- data items with different life histories
- no obvious prime key.

I'd strongly suggest that you reduce your data elements to Third Normal
Form (3NF) and produce an entity-relationship diagram from that. Then you
can define prime and foreign keys and an easily implemented schema. This
leaves you in a position to reload your data into the redesigned
database. Your data is relatively simple, so you should be able to do
that in 1-2 days.

You'll find designing and writing programs against a 3NF schema rather
easier than doing so for an artificially flattened structure.
 
E

er.yogeshkhandelwal

RedGrittyBrick  wrote:
I have attached my xml file and database columns name...

OK but that isn't an SSCCE as described athttp://sscce.org.
and also
writing this program because i don't want any dependency on XSD..

You'll need a mapping from XML tags and attributes to the column-names
of your database table.




<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/> [...]

column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule [...]
I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component

I'm not familiar with JAXB but there are certainly DOM and SAX parsers
that don't require XSD.
to finish this task

Have you already finished this task?
but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..

Unless your XML tag and attribute names can be inferred from the column
names (or vice versa) - you can't write a truly generic program that
deals with any arbitrary XML and corresponding tables. Particularly as,
in your example, the XML isn't flat (you have <home-team><teamname> and
<visiting-team><team-name> corresponding to HOME_TEAM_NAME and
VISIT_TEAM_NAME respectively).

You could parse the XML using DOM, extract the elements that correspond
to the record key for the database table, lookup the record using JDBC,
Hibernate etc, then extract every element from the DOM document and
compare the values with those obtained by the database. The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

Is this what you want to do?

If so, which part are you having problems with?

The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

I'm able to parse the XML and also able to fetch the column name and
data from db table but not getting how do i map it with the XML tags
and attributes.I know i have to read it from configuration file but
don't know how do i do it.please tell me how do i do.

Thanks,
 
E

er.yogeshkhandelwal

RedGrittyBrick  wrote:
I have attached my xml file and database columns name...

OK but that isn't an SSCCE as described athttp://sscce.org.
and also
writing this program because i don't want any dependency on XSD..

You'll need a mapping from XML tags and attributes to the column-names
of your database table.




<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/> [...]

column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule [...]
I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component

I'm not familiar with JAXB but there are certainly DOM and SAX parsers
that don't require XSD.
to finish this task

Have you already finished this task?
but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..

Unless your XML tag and attribute names can be inferred from the column
names (or vice versa) - you can't write a truly generic program that
deals with any arbitrary XML and corresponding tables. Particularly as,
in your example, the XML isn't flat (you have <home-team><teamname> and
<visiting-team><team-name> corresponding to HOME_TEAM_NAME and
VISIT_TEAM_NAME respectively).

You could parse the XML using DOM, extract the elements that correspond
to the record key for the database table, lookup the record using JDBC,
Hibernate etc, then extract every element from the DOM document and
compare the values with those obtained by the database. The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

Is this what you want to do?

If so, which part are you having problems with?

The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

I'm able to parse the XML and also able to fetch the column name and
data from db table but not getting how do i map it with the XML tags
and attributes.I know i have to read it from configuration file but
don't know how do i do it.please tell me how do i do.

Thanks,
 
E

er.yogeshkhandelwal

RedGrittyBrick  wrote:
I have attached my xml file and database columns name...

OK but that isn't an SSCCE as described athttp://sscce.org.
and also
writing this program because i don't want any dependency on XSD..

You'll need a mapping from XML tags and attributes to the column-names
of your database table.




<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/> [...]

column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule [...]
I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component

I'm not familiar with JAXB but there are certainly DOM and SAX parsers
that don't require XSD.
to finish this task

Have you already finished this task?
but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..

Unless your XML tag and attribute names can be inferred from the column
names (or vice versa) - you can't write a truly generic program that
deals with any arbitrary XML and corresponding tables. Particularly as,
in your example, the XML isn't flat (you have <home-team><teamname> and
<visiting-team><team-name> corresponding to HOME_TEAM_NAME and
VISIT_TEAM_NAME respectively).

You could parse the XML using DOM, extract the elements that correspond
to the record key for the database table, lookup the record using JDBC,
Hibernate etc, then extract every element from the DOM document and
compare the values with those obtained by the database. The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

Is this what you want to do?

If so, which part are you having problems with?

The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

I'm able to parse the XML and also able to fetch the column name and
data from db table but not getting how do i map it with the XML tags
and attributes.I know i have to read it from configuration file but
don't know how do i do it.please tell me how do i do.

Thanks,
 
E

er.yogeshkhandelwal

RedGrittyBrick  wrote:
I have attached my xml file and database columns name...

OK but that isn't an SSCCE as described athttp://sscce.org.
and also
writing this program because i don't want any dependency on XSD..

You'll need a mapping from XML tags and attributes to the column-names
of your database table.




<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/> [...]

column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule [...]
I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component

I'm not familiar with JAXB but there are certainly DOM and SAX parsers
that don't require XSD.
to finish this task

Have you already finished this task?
but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..

Unless your XML tag and attribute names can be inferred from the column
names (or vice versa) - you can't write a truly generic program that
deals with any arbitrary XML and corresponding tables. Particularly as,
in your example, the XML isn't flat (you have <home-team><teamname> and
<visiting-team><team-name> corresponding to HOME_TEAM_NAME and
VISIT_TEAM_NAME respectively).

You could parse the XML using DOM, extract the elements that correspond
to the record key for the database table, lookup the record using JDBC,
Hibernate etc, then extract every element from the DOM document and
compare the values with those obtained by the database. The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

Is this what you want to do?

If so, which part are you having problems with?

The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

I'm able to parse the XML and also able to fetch the column name and
data from db table but not getting how do i map it with the XML tags
and attributes.I know i have to read it from configuration file but
don't know how do i do it.please tell me how do i do.

Thanks,
 
E

er.yogeshkhandelwal

RedGrittyBrick  wrote:
I have attached my xml file and database columns name...

OK but that isn't an SSCCE as described athttp://sscce.org.
and also
writing this program because i don't want any dependency on XSD..

You'll need a mapping from XML tags and attributes to the column-names
of your database table.




<?xml version="1.0" encoding="UTF-8"?>
<cfb-schedule-document>
<sports-statistics>
<sports-schedule>
<date year="2007" month="10" date="09" day="3"/>
<time hour="00" minute="29" timezone="Eastern"/>
<season season="2007"/> [...]

column name=MODIFIED_DATETIME table=cfb_schedule
column name=MODIFIED_BY table=cfb_schedule
column name=FEED_DATETIME table=cfb_schedule
column name=SEASON table=cfb_schedule [...]
I want to compare the XML attribute which is having data with the
database and also don't want any dependecies on XSD..right now i'm
using JAXB component

I'm not familiar with JAXB but there are certainly DOM and SAX parsers
that don't require XSD.
to finish this task

Have you already finished this task?
but i want to make one
generic program by which i can parse XML,can read all data and can
compare data with database(which we have already inserted into
database).It's just like crosschecking it..Please provide me the best
solution for this.Thanks in advance..

Unless your XML tag and attribute names can be inferred from the column
names (or vice versa) - you can't write a truly generic program that
deals with any arbitrary XML and corresponding tables. Particularly as,
in your example, the XML isn't flat (you have <home-team><teamname> and
<visiting-team><team-name> corresponding to HOME_TEAM_NAME and
VISIT_TEAM_NAME respectively).

You could parse the XML using DOM, extract the elements that correspond
to the record key for the database table, lookup the record using JDBC,
Hibernate etc, then extract every element from the DOM document and
compare the values with those obtained by the database. The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

Is this what you want to do?

If so, which part are you having problems with?

The program has
to know the tag-names and column names - either hardcoded or read from a
configuration file.

I'm able to parse the XML and also able to fetch the column name and
data from db table but not getting how do i map it with the XML tags
and attributes.I know i have to read it from configuration file but
don't know how do i do it.please tell me how do i do.

Thanks,
 

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,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top