Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes XML and Related Technologies and the fly likes XML Reading vs. MySQL Querying. which one should I choose? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML Reading vs. MySQL Querying. which one should I choose? " Watch "XML Reading vs. MySQL Querying. which one should I choose? " New topic
Author

XML Reading vs. MySQL Querying. which one should I choose?

Khosrow Moossavi
Greenhorn

Joined: Aug 08, 2005
Posts: 26
Hi,

I'm trying to develope a Database-XML driven site, and I've faced something that made me choose between these two options I have.
  • Reading XML Document to find the value i'm looking for.
  • Perform a Query to MySQL and getting my result back.


  • The exact situation is this. In the XML Document there are 3 main sections.
  • Categories (aprox. 5,000 records)
  • Locations (aprox. 400 records)
  • Profiles (aprox. 70,000 records (while growing))


  • I was trying to generate my website urls like this :
    http://www.mywebsite.com/<Argument>
    this is common between all of the above 3 sections.

    So I'm doing it now like this :
    Searching XML Document for the <Argument> and when I find it, retrieve the ID. which might be started with *cat-*, *loc-* or *pro-*. So now I know the Type of the Argument and show the content corresponding to that type.

    Is this a good approach or should I leave it alone and try to query database?
    I'm having 3 different tables to store them. Is this not gonna make visitors lose some times? because I have to search 3 tables (at the worst scenario!)

    In this worst scenario, is it faster to query 3 different tables secuentially, or searching the XML Document?

    I'm using Tomcat on linux, and the PL is Java, by the way.

    Any comment would be highly welcome!

    Thanks.


    SCJP and SCWCD are going to be installed here.
    Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18656
        
        8

    It depends how you do it.

    If you just store a big XML document and parse the whole thing every time you get a request, then your response time will be far too long. But if you index the XML document and make some kind of "XML database" out of it, then you might have something workable.

    Likewise if you create a database with no indexes, then you would have to search the whole table for every request. That would be a slower-downer too.

    However it's very easy to create an index for a database table. Whereas indexing an XML document is not something that you could do this afternoon. If I had the choice of using a database or an XML document to store data which is naturally table-structured and not tree-structured, I would use the database pretty much automatically. And that's what you have, as far as I can tell. I don't see anything to make me choose XML at all.
    Khosrow Moossavi
    Greenhorn

    Joined: Aug 08, 2005
    Posts: 26
    Hi Paul,
    Thanks for your response.
    The thing is I kinda have to use the XML. Because this is multilingual Website, and I'm handling the different Language Elements via XML document (Using XML Doc as a Dictionary) - Is this a good approach for multilingual websites ?? - and the usage of XML in the current situation is inevitable for me.
    So if I would go for the xml solution, you've said I have to index it. I've searched for Indexing XML Document, and I've found different things like: Lucene, Nuch, Compass, Hadoop, ...
    what are these? am I finding the right path? did you mean one of these?
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12804
        
        5
    If you need to locate a particular Element (org.w3c.dom.Element) according to some key word - possibly an attribute or other text, you can use Java collections such as HashMap to store a reference to that Element by that key. This gives mind boggling-ly fast lookups.

    More complex look-up for a specific Element might be handled by XPath and XQuery style searches. There is no need to venture outside the standard Java library - see javax.xml.xpath package in Java 1.5 et seq.

    Bill
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: XML Reading vs. MySQL Querying. which one should I choose?