aspose file tools*
The moose likes XML and Related Technologies and the fly likes Looking for some opinions on how to write effective XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Looking for some opinions on how to write effective XML" Watch "Looking for some opinions on how to write effective XML" New topic
Author

Looking for some opinions on how to write effective XML

Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
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 ]
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
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 ]
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
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 ]

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Chris Stewart
Ranch Hand

Joined: Sep 29, 2001
Posts: 124
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
Sheriff

Joined: Aug 26, 2000
Posts: 10065
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

Joined: Sep 29, 2001
Posts: 124
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Looking for some opinions on how to write effective XML