473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Advice for the XML to db problem

OK,

I've hit the problem enough now to want to know what is the easy way
:-) Anybody know?

I read in microsoft.public.sqlserver.xml group about doing this:
1) Create an XML schema from the db schema using a tool like
http://www.microsoft.com/downloads/d...displaylang=en
2) Map the schema using a tool like MapForce
3) Use MSFT's version of BulkLoad to load up the incoming XML:
http://msdn.microsoft.com/library/de...kload_6bos.asp

Also, XMLSpy's MapForce says it does db-to-xml but does nowhere say
it does xml-to-db. Anyone know if it does? Clearly the interesting
cases is when the incoming XML in no way matches the schema and
complex mapping including determingin whether to overwrite, add to, or
ignore is needed (such as recording a jacket style for a person).

Has anyone already addressed these issues or have comments? To date
I have done systems using custom Java coding that does the mapping as
well as ones that do some meta-coding by mapping matching db columns
to matching XML Element names. As well, have used some XSLT to get
into a "standard" XML and then loaded into the db from there.

Ideally I think I should be able to open a tool and refer to the db
and to the incoming schema. Then mapping should occur fairly
dynamically (saw a presentation in school about some project doing
this but did not write down the four tools quoted as already doing
it), then I go and check over the mappings. Lastly, some external
config is used each time to control whether to over-write, if/how to
create new records, or to ignore on pre-existing. Does this exist?

TIA,
TimJowers
Jul 20 '05 #1
1 1880
If you're using java you can combine JDOM and JDBC techology to
create a method that will use JDBC meta data to fetch column
names from the database and then build JDOM Elements.

That kind of gives you what you want. The ability to make sql
queries and get a List of JDOM Elements or a single JDOM Element.

public static Element DoQueryAsElement( String sql , String label
)
throws ChainedException {
BbConnection dbc = null;
Element xmlData = null;
try {
dbc = new BbConnection();
dbc.ProcessSQL(sql);
xmlData = new Element( label + "s");
while ( dbc.getResultSet().next() ) { // right indent to
make easy to read
int ccnt = dbc.getResultSet().getMetaData().getColumnCount();
Element elm = new Element(label);
for( int i = 1 ; i <= ccnt ; i ++ )
{
String colName =
dbc.getResultSet().getMetaData().getColumnName(i);
String content = dbc.SQLHelper(dbc.getResultSet().getString(i));
elm.addContent(new
Element(colName.toLowerCase()).addContent(content) );
}
xmlData.addContent(elm);
}
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoQueryAsElement failed
: " + label + ":" + sql ) );
}
finally
{
try {
dbc.closeResultSet();
dbc.closeStatement();
dbc.closeConnection();
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoQueryAsElement
failed : " + sql ) );
}
}
return xmlData;
}

public static Element DoQuerySelectRow( String sql , String label
)
throws ChainedException {
BbConnection dbc = null;
Element xmlData = null;
try {
dbc = new BbConnection();
dbc.ProcessSQL(sql);
xmlData = new Element( label );
dbc.getResultSet().next();
int ccnt = dbc.getResultSet().getMetaData().getColumnCount();
for( int i = 1 ; i <= ccnt ; i ++ )
{
String colName =
dbc.getResultSet().getMetaData().getColumnName(i);
String content = dbc.SQLHelper(dbc.getResultSet().getString(i));
xmlData.addContent(new
Element(colName.toLowerCase()).addContent(content) );
}
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoQuerySingleRow failed : " + label
+ ":" + sql ) );
}
finally
{
try {
dbc.closeResultSet();
dbc.closeStatement();
dbc.closeConnection();
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoQuerySingleRow
failed : " + sql ) );
}
}
return xmlData;
}
public static ArrayList DoQueryAsStringList( String sql )
throws ChainedException {
BbConnection dbc = null;
ArrayList v = new ArrayList();
try {
dbc = new BbConnection();
dbc.ProcessSQL(sql);
while ( dbc.getResultSet().next() ) {
v.add(dbc.getResultSet().getString(1));
}
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoArrayList failed : "
+ sql ) );
}
finally
{
try {
dbc.closeResultSet();
dbc.closeStatement();
dbc.closeConnection();
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoArrayList failed
: " + sql ) );
}
}
return v;
}

public static List DoQueryAsElementList( String sql , String label
)
throws ChainedException {
BbConnection dbc = null;
ArrayList v = new ArrayList();
try {
dbc = new BbConnection();
dbc.ProcessSQL(sql);
while ( dbc.getResultSet().next() ) {
// See note 1 below
int ccnt = dbc.getResultSet().getMetaData().getColumnCount();
Element elm = new Element(label);
for( int i = 1 ; i <= ccnt ; i ++ )
{
String colName =
dbc.getResultSet().getMetaData().getColumnName(i);
String content = dbc.SQLHelper(dbc.getResultSet().getString(i));
elm.addContent(new
Element(colName.toLowerCase()).addContent(content) );
}
v.add(elm);
}
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoQueryAsElementList failed :(" +
label + "):" + sql ) );
}
finally
{
try {
dbc.closeResultSet();
dbc.closeStatement();
dbc.closeConnection();
} catch ( Exception ex ) {
throw ( new ChainedException( ex, "DoQueryAsElementList failed :(" +
label + "):" + sql ) );
}
}
return v;
}
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

75
by: Howard Nease | last post by:
Hello, everyone. I would appreciate any advice that someone could give me on my future career path. Here is my situation: I am a bright Junior in a very well-respected private high school, taking...
9
by: Rick Muller | last post by:
I have a problem that I would like to get some advice on from other Pythonistas. I currently manage a (soon to be) open source project for displaying molecular graphics for a variety of different...
4
by: Bob | last post by:
Hallo, I have to make a web application in Javascript/ASP for tenniscourt reservation (based on Access database). I would like to do everything with one page, because the user must be able to...
7
by: dthmtlgod | last post by:
I am creating a online help desk for my office. I am attempting to cleanup my code and I was hoping for a little advice. I have 30 different categories of requests ranging from the desktop...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
2
by: andyjgw | last post by:
Hi I'm a bit new to the designing of custom web page controls and using them in the properties designer window - need a little advice on a concept here. I have two properties in my control -...
6
by: J Rieggle | last post by:
Hi there, I am stuck on a problem that relates to eCommerce sites, but isnt ASP.NET specific (sorry). The ecommerce site is working in the UK, and products will be sold in pounds stirling. ...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
23
by: JohnH | last post by:
I'm just recently come to work for an auto brokerage firm. My position involves performing mysterious rites, rituals and magick in order to get information out of their access database. This is...
7
by: SM | last post by:
Hello, I have a index.php template (2 columns). The right columns contains a bunch of links (interviews, poems, etc...) The left columns contains the actual article. So if I click on a link on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.