jQuery in Action, 2nd edition*
The moose likes XML and Related Technologies and the fly likes XML vs. database 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 "XML vs. database" Watch "XML vs. database" New topic
Author

XML vs. database

lydia westland
Ranch Hand

Joined: Feb 24, 2002
Posts: 72
I've seen XML is useful as a data exchange mechanism, as a format tool, and for the seperation of content and structure. but as a data storage, I have two questions:
1. I am thinking database has more advantage over XML, is that true? For example, database has a lot of tools and may be faster in querying.
2. I've never use the import XML function in database. XML employs tree structure, while most commercial database user tables and relationships, how do they import "XML"?
Thank you for explaination


Lydia<br />~~~~~~~~~~~~<br />I love Italy team.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It seems a strangely common assumption that XML is some sort of database. However XML is not a form of data storage, it is a form of data markup. Even if you mark up your data in XML, you still have to store it somewhere if you want to keep it around. An XML document-tree can be stored in a text file, for example, or it can be stored in a database, or it can be stored in a LDAP repository, or whatever.
Considering databases in particular, there are essentially two ways of storing XML-marked-up data in a database :- as whole documents; or decomposed.
To store some XML data as a whole document you might export a DOM tree as a text file and store it in a CLOB or BLOB column.
To store a decomposed XML document you might either use domain knowledge to represent the same data in a relational form, or simply "flatten" the document into a key/value map and store that in a table. "Flattening" is something a lot of XML users are not very aware of, but works like this:
Take an XML tree, for example:
<team>
<person sex='male'>
<name>Frank Carver</name>
<location>England</location>
</person>
<person sex='female'>
<name>Mapraputa Is</name>
<location>USA</location>
</person>
</team>
When "flattened" it might look like
team.person[0].@sex=male
team.person[0].name[0]=Frank Carver
team.person[0].location[0]=England
team.person[1].@sex=female
team.person[1].name[0]=Mapraputa Is
team.person[1].location[0]=USA
Note that the exact method used to generate the left-hand side "key" varies, but the important thing is that it encodes enough information to regenerate the same XML document.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Devrim Turker
Greenhorn

Joined: Jan 14, 2002
Posts: 14
http://www.cs.washington.edu/education/courses/cse326/01sp/lecture8.ppt
http://www.cs.washington.edu/education/courses/cse544/00sp/lectures/ppt/l3.ppt
hypersonic database (used by jboss) uses AVL tree
for storage
sapdb also uses AVL tree.
perhaps indexing logic is used for storage now
have fun
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
1. I am thinking database has more advantage over XML, is that true? For example, database has a lot of tools and may be faster in querying.
Abolutely. Here is my canned list of database virtues:
transactional integrity
security
authentication
concurrency control
data validation and conversion
search mechanism
XML was created as a substitution for HTML to allow "meaningful" markup, so search engines could do better job etc. Looking at what it becomes... Here is a quote from XMLHack: "Edd Dumbill opens the XML Europe 2002 conference by questioning whether XML has become the "SGML on the Web" which it was meant to be.
"XML has achieved more than we could believe and is even ridiculously widespread to the point that we find it in the configuration files of our PC. It's been used to integrate to web web cell phones and set top boxes and is even been taught in the universities. "
http://xmlhack.com/read.php?item=1654
2. I've never use the import XML function in database. XML employs tree structure, while most commercial database user tables and relationships, how do they import "XML"?
To add to what is already said, chances are that imported XML is nothing but another database's unload - i.e. the very tables represented as a tree. I would love to see statistics on what percent of XML documents have table-like nature.
--------------------
"There are no answers, only cross references."
 
Consider Paul's rocket mass heater.
 
subject: XML vs. database
 
Similar Threads
XML to database
Storing parsed XML data into database
How to connect applet to database
xml conversion
How to store whole XML in a table of a database