aspose file tools
The moose likes XML and Related Technologies and the fly likes XML or the Database ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Reply Bookmark "XML or the Database ?" Watch "XML or the Database ?" New topic
Author

XML or the Database ?

Doshi Milan
Ranch Hand

Joined: May 29, 2001
Posts: 112
Dear Friends,
An intresting interview question which was asked to me.
Let us say that there is an XML Document which contains the same piece of information as contained in an Employee table of a particular database. If I send a querry as to Select all the Marketing personnels working in India and having Salary less than X amount. Then in which case will the output be faster and why ?
I am not a pro in XML and an indepth reply will help me to understand things better.
Thanks in advance,
Regards,
Milan Doshi
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
The answer really depends on how big the XML document is. Since the XML document is just a plain flat text-based entity, it will not have advanced features otherwise present in relational databases such as indexing, search optimization etc. Having said that, one can always build XML documents to facilitate quick searching. For instance, frequently used search fields can be assigned unique IDs in the document.
If you compare two scenarios ie., sending the resultset as an XML document versus sending the SQL query and have the end user execute the query, the pros and cons can be summarized as follows -
  • The XML document can be used any number of times once it is received at the other end ; whereas the SQL will have to be tweaked and executed each time the user wishes to see a variation of the result set.
  • By not giving the actual SQL to the user, you can avoid sharing database access details such as user id, password, instance information etc with the user who is by the way, only interested in data, not how to procure the data.
  • With some good design, we can let the user reformat the XML for any desired presentation while not changing the underlying data. SQL resultsets do not offer this flexibility unless you introduce a facade of formatting logic.
  • Last but not the least, delivering the data as XML and not as a set of SQL statements help you achieve a greater degree of data abstraction. If your table structures change in future, you don't have to "fix" the SQL and send it to all the 100 client bases again!


  • Hope this gives you some food for thought


    Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
    Doshi Milan
    Ranch Hand

    Joined: May 29, 2001
    Posts: 112
    Thanks Ajit,
    It is quite intresting and I`ll go more in depth in this.
    Regards,
    Milan Doshi
    Doug Wang
    Ranch Hand

    Joined: Oct 05, 2001
    Posts: 445
    It is more interesting for me is that XSLT can query XML just as SQL language does with database.
    Cheers,
    Doug.
    [ January 17, 2002: Message edited by: Doug Wang ]

    Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep
    Doug Wang
    Ranch Hand

    Joined: Oct 05, 2001
    Posts: 445
    Originally posted by Ajith Kallambella:
    If you compare two scenarios ie., sending the resultset as an XML document versus sending the SQL query and have the end user execute the query, the pros and cons can be summarized as follows -
    Ajith, one more pro of XML I'd like to supplement is,
    When you get the XML document of your resultset, you can send it to end users of any platform, that is, you may send it to Windows user, Linux user, Mac user, or....

    Doug.
     
    I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
     
    subject: XML or the Database ?
     
    Similar Threads
    Hibernate with RSS Feeds.
    creating xml suing jsp
    How to pass an XML to a servlet.
    XML Database and CMP
    Plz let me know how to pass an XML to servlet