views:

269

answers:

9

I have a lightweight online shopping site based on JSP and XML, and I'm wondering what the particular weaknesses of this system are as opposed to, say, PHP and MySQL?

I know JSP can use Java APIs, but I feel PHP has a more "natural" relationship with HTML and also has the benefits of being dynamically typed, and is far more widespread and in-demand. Is there a reason for this?

+16  A: 

I would say the main disadvantages of the XML solution over a database one would be:

  1. search speed
  2. update speed
  3. scalability
  4. concurrency (thanks Jonathan)
Galwegian
Not to mention that once the site is successful, you could have concurrency problems that a DBMS solves.
Jonathan Leffler
XML is great for data transport. It loses some of its charms when used as a relational data repository.
Matthew Whited
A: 

Using XML as data storage for a e-commerce isn't that usual because of performance issues and, well, because (My)SQL works so well. If you want to try something new, swap XML with MySQL. I don't see any real benefits with changing the programming language, in fact, I think you'll notice a significant productivity dip if you change languages.

Amin Amini
+2  A: 

PHP is generally more widespread and in demand because it has a very small learning curve and is easy for a casual developer to pick up and begin using. It also doesn't hurt that it usually comes bundled with most Apache installs on linux-based servers.

As a result of the above, there are many more good (and bad!) resources available to help a fledgling developer for PHP than just about any language out there, which creates a snowball effect.

To answer your original question concerning XML, a basic shopping cart implementation on a low-volume store with very few items probably wouldn't break down using the architecture you're describing, but actions like searching an item database, tracking inventory and such are best left to a database.

That said, changing to a database doesn't mean you need to move off of JSP if that's what you're already working with.

AvatarKava
A: 

Related, but off topic: did you say "lightweight"? in that case, sqlite could beat both XML and Database..

Here Be Wolves
sqlite *is* a database
Mauricio Scheffer
agreed, but it is not as heavy as a database *server*
Here Be Wolves
continued: and it is faster than using XML
Here Be Wolves
+1  A: 

If you are in a situation where you anticipate having relationships between entities, I have found XML to be significantly more difficult to work with than a relationship database. Not only does determining what relationships exist cause problems (requiring you to either maintain a map of these relationships in memory or to read in large sets of files repeatedly), but maintaining referential integrity is a terrible pain with XML. Even something as simple as classifying items according to some taxonomy (X is a lawnmower is a kind of outdoor equipment is a kind of...) becomes a problem with XML, as you will have to develop some external tools to ensure that you are using a consistent vocabulary. With a RDBMS, you just have a table of terms which have parent and children IDs. Any item in the store can just refer to the taxonomy IDs.

When I have have tried to do too much with XML, I've found myself crudely recreating some of the most useful features of an RDBMS with a sloppy collection of external tools.

jmans
+5  A: 

Lightweight is relative. Go for the database solution. You never know when your "lightweight" site becomes "mission-critical"

AZ
A: 

If you're storing only transactional data you don't have any problems that an RDB would not solve. But if your data is more document-oriented (messier), you may want to look at any of several native xml DBs and their XQuery interfaces.

eXist, Documentum xDB, Oracle Berkeley, MarkLogic (for big stuff) are just a few. You might also be interested in http://en.wikibooks.org/wiki/XRX

A: 

On a different tack, you could look at json in couchdb.

ontangent
+2  A: 

I have a lightweight online shopping site based on JSP and XML, and I'm wondering what the particular weaknesses of this system are as opposed to, say, PHP and MySQL?

JSP and PHP are both view technologies. JSP has the advantage of being backed by Java (EE) which is a strong language and platform. PHP has the advantage of being the easiest and most public adoptable web programming language ever. The disadvantages speaks for itself.

To develop a robust webapplication following the OO ideology, pick JSP (as long as you don't embed raw Java code in it the '90s way using scriptlets). If you're in a hurry and/or don't care about future maintainability and want to develop an e-commerce website in one day, then pick PHP.

XML and RDBMS are both ways to store data. RDBMS in turn, however, offers the ability to use SQL as language to select and manipulate specific data which can be done tremendously much more efficient than ever possible with XML.

Comparing JSP+XML with PHP+MySQL is a bit like comparing apples with oranges. XML however bites you much more as being a data store, so you would really prefer MySQL "in spite of" that it goes with PHP. You can however access databases as good with Java. To start, there you have the JDBC API for. All with all, I'd prefer JSP+SQL.

I know JSP can use Java APIs, but I feel PHP has a more "natural" relationship with HTML and also has the benefits of being dynamically typed, and is far more widespread and in-demand. Is there a reason for this?

It's the most easy to pickup by ones knowing absolutely nothing about programming. All you need to have is a simple webserver and a texteditor. It's very fast to develop with PHP as it has instant feedback and there are countless tutorials and code snippets available on the web. Further you have also much more choice of free PHP web hosting while you have to pay a bit more for a solid JSP/Servlet hosting.

BalusC