• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Looking for some opinions on how to write effective XML

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say you were going to write an XML file that replaced the framework of a database. How would you guys go about this? Here is where I am now...


In the end I'd like to be able to write an application that will build the database outlined in my xml file. Any advice on xml creation or parser usage? Thanks in advance.
[ June 24, 2002: Message edited by: Mapraputa Is ]
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice idea.
Are you trying to create .sql files with create table statements after parsing the xml?
u have figured out a neat of learning xml, parsing concepts! great.


then you might want to make some columns of type ID? (ie primary key?)
refer to them from other places to specify foreign key constraints? so they w'd be of the type IDREF. An attribute of type IDREF can take any value that is of the type ID
So i don't think it can give the effect of a database constraint though.
If somebody can throw some light on using xml as database, that will be great!
Some thoughts here..
If we have an element named <database>, i tend not to repeat the same name while declaring an element (for eg name). My feeling is that we can probably have <name> instead of <databaseName>. Please feel free ignore these suggestions though as am not sure if i can safely extend java conventions to xml as well !
Actually lot of people whom i know prefer this convention when naming java packages as well.
com.i2.iquote.Controller
to
com.i2.iquote.IQuoteController
class Customer{
getName() instead of getCustomerName()
}
in the above cases Customer and IQuote have been found to be redundant.
Frankly, such tendencies to extend concepts picked up from a different environment
backfired in other places.
I can clearly remember that Python's way of using exceptions seemed to be quite different from that of java and i was told not to carry my java knowledge to python.
i can already see some problems if we are looking for ,say, the name of a column.
Doing
doc.getElementsByTagName("columName"); w'd fetch all the column names
whereas if i follow what i said eariler, i need to get to "column" element first before doing getElementsByTagName("Name");
can someone point out the conventions used while naming xml elements?
thanks!
[ June 24, 2002: Message edited by: Mapraputa Is ]
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can just use attributes to carry names, as you did with <data> tag. Then your XML will be

In the end I'd like to be able to write an application that will build the database outlined in my xml file.
If you want to generate SQL command to create tables, then you can use XSLT and your framework will look like

output:

I cannot guarantee my SQL is correct, though.
But I am sure there are tools for "XML to SQL" mapping, you may want to investigate, unless it's an educational exercise.
[ June 24, 2002: Message edited by: Mapraputa Is ]
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, this is looking really good. I'm just trying to make an easy way to create a database script from a Java app. I've never really seen anything on XSLT, would anyone feel like giving a quick overview and common uses? Thanks guys, you're helping a lot.
Mapraputa Is, in your example above, how did you have the xsl file use the xml file for finding the values?
[ June 24, 2002: Message edited by: Chris Stewart ]
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Xalan for XSL transformations and I am just calling it from command line:
java org.apache.xalan.xslt.Process -in [xml file] -xsl [xsl file] -out [output file]
But it can be called from your Java program also.
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got everything working like I wanted. This will create a database from the framework you give in an XML file. Here you go...
XML File

XSL File

Java Class

[ June 25, 2002: Message edited by: Chris Stewart ]
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic