Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why XML? Why not databases? 7

Status
Not open for further replies.

jimmywages

Programmer
Dec 12, 2002
11
US
Hello everybody.

I'm new to XML and to be honest I haven't done much in XML other than the basic "your first XML document" kind of stuff. But as I was learning more and more about XML, it seemed to me to be redundant and even useless.

From what I read on the internet, it seems that XML is basically a text file that contained records. Well, why use XML? Why not just use databases if you want records of data!?!? I've used databases in collaboration with many HTML and Flash pages and it's worked great. It keeps the data seperate from the design AND it is searchable, query-able, etc. (is XML searchable and query-able? I don't know, please inform me).

Anyway, I just don't see the advantage of XML from a functional point of view. What can it do that databases can't? What is the fundamental difference of the two? Please enlighten me.

Thank you very much,

~jimmy.
 
jimmy,

XML is searchable and queryable. You can use an XML language called XPath to query the branches in an xml document, but it is not perfect, especially "cross-table" queries where XPath falls over.

You can also use the DOM to programmatically traverse/query the xml, but this is nowhere near as good as good old SQL which is so much more simple and quick.

XMl is also plausable for making backups, especially as XML is basically text it is cross-platform compatible.

XML can also be used for displaying the data in different ways to different people using XSL stylesheets.

Apart from this, from what i have found so far, databases are better at indexing, security, transactions the list goes on.

MrPeds

 
Thanks for your reply MrPeds!

I'm still curious as to what advantages XML has over databases (other than cross platform compatibility). Databases can also be used to display the same data in different ways using different style sheets etc. So yeah, I'd really like to use XML, but I need to know how to fully utilize its strengths. When would I use XML for instance over databases?

~jimmy.
 
Hi Jimmy,

There is more to XML than database. The scope is much more vast than that. Database is just a small piece of the puzzle when you are talking XML. XML is not a language nor a script nor a database. It is more of a ***specification*** or encoding scheme that has been standardize and globally accepted. It is really the most standard means of communicating between platforms whether it may be hardware, OS, software or whatever. It is independent of all of these. Soap uses XML encoding. Web services uses XML encoding blah blah blah.

But to answer your question specifically...There is really no compelling advantages of XML over a database if you live in a vacuum by yourself and your system didn't need to collaborate or communicate with anyone else.

Rico
 
Jimmy,

On another note...XML doesn't really compete with a database. It complements it.

Rico
 
I use XML extensively in my applications, but not as a datastore. I use it as a data transmission medium. I store my data in SQL Server 200 in a normalised data model. I use SQL2000's XML functrionality to return the data that I want as an XML document rather than a recordset. This allows fatser transmission across th wire and allows me to use XPath to get at specific dat within the results set very easily, and I can also process the data using the DOM, or display it using XSLT via ASP.

In some cases it might be useful to store the data as XML rather than in a database, but in applications with a large or complicated dataset then keep it in a database. The power in XML is to act as a presentation method for this data, and then reap the benefits associated with that via XPath, XSLT, and the DOM.

If you take a look at .NET ADO.NET is XML behind the scenes so that should give you an idea of what Microsoft views about the usefullness of XML. The .Net framework and ASP.NET have a vast amount of XML related functionlaity built in to take full adavantage.

Not to sure about other products but I do know that Oracle put a lot of effort into utilising it.

James :) James Culshaw
james@miniaturereview.co.uk
 
I have to agree that while in certain areas XML and databases "compete", they are really different tools offering different features. Here are areas where XML has the advantage:

1) irregular data structure: take your average XHTML page (or HTML -- the idea is the same, just don't complain that HTML isn't XML!) - it doesn't fit into regular records. Certain areas do, like tables, but usually you're dealing with a massively hierarchical non-standardized data. You could figure out ways to make it work in a database, but not as cleanly or easily as XML. (you can always pound in a nail with a wrench...)

2) XML has built-in validation: you can duplicate this in databases, but it's already built in with XML. This is both structure (with DTD's and schemas) and content (schemas). You can easily choose not to validate (another feature, IHMO!)

3) XML can be read without XML tools: Only if databases are exported to text can they do this (or if they store data as text)

4) XML ties in to other related technologies: XSL is an entire language meant for translating and formatting XML. There are similar tools for database data, but integration doesn't seem as clean.

5) XML is very easily used as a message a.k.a. "cross-platform / cross-tool communication"

Keep in mind that XML isn't meant to be a high-performance storage medium. You CAN have it act as a persistant data store, and if you work at it you can get it to be pretty quick, but I'll take a database any day for that.

Also, XML seems to have two usages right now:
1) Data-centric: Using XML to store a collection of records. This is probably what you thought of when comparing databases to XML. XML is probably better as being an easy medium to SEND a bunch of records for processing by other systems (again, cross-platform communication). A database would STORE a bunch of records.

2) Document-centric: Using XML to store documents -- this is the massively hierarchical non-standardized data. Your word document could EASILY be formatted as XML, but less easily stored as a collection of database records. Note that large quantities of XML documents would probably be stored in a database! Database determines which document and delivers it -- XML handles the intra-document content.

Further, here is a great link to check out:
 
Thanks for all the replies, y'all. I think I'm beginning to see the light.

~jimmy.
 
Hey,
Reading your postings also helped me explain somethings about xml. i'm new to it and I've been wondering why i should use it instead of the database. it just seems to be an extra and unnecessary step to take in presenting data. I'll continue to delve into it. Thanks
 
hey there,

Personally I don't see what all the hype about XML is all about. Yeah it might be all right for "cross-platform / cross-tool communication", but any old text file could do that and tie up much less system resources.

XML has to have so many tags that are repeated over and over again. Very inefficient. Quite often, I find, there is just as much or more meta data (tags) then real data (what you're storing/communicating). This ties up much more memory then necessary, with stuff that you won't even be using in the end. XML would also take more time to parse, tying up processing time.

What I've noticed, up to now, is that anything that XML does can be done more efficiently using alternative methods.
________________________
JoelMac
 
That's absolutely correct Joel. A tag like this...

<Apartment:Number>2</Apartment:Number>

...is absolutely ridiculous. Defineately bloated with metadata. It's very obvious that there is something wrong with this and wonder what happens when the http transport sees this...what does it do? Does it compress it before it is pushed to the internet? Maybe it's only bloated when it is presented. I don't know.

But like I said, it's a standard. The whole dotnet thing rides on XML. Everybody is embracing it.

XML doesn't look like it's geared for speed but keep this in mind...If you are a company and decide to partner with another company, if both parties have embraced XML then sharing process methods, properties via SOAP will make the merge painless. Also, web-services are important too. WSDL is all XML encoding. The whole world is networked together and XML is the common link for every system to communicate to one another.

Although, the one thing that worries me about XML is security since it is so open.
 
joelmac: Just to comment, yes sending text in your own text formt would work just fine. Until you have to explain to another programmer that column 1 is for this and column 2 is for this and column 3 is for that, etc. I have done several projects in the past and had to deal with keeping track of the key for my text files so that I could remember what all the differant positions were for (ie comma delimited or tab delimited files).
XML merely gives everyone a standard way to exncapsulate this data in a format that is more easily remembered and more easily parsed. The fact that almost every language out there these days has a parser means that you wouldn't have to re-invent the wheel everytime you wish to transport data in a text file.

Concerning data storage: Say you have a digital library. According to the most recent standards (in XML I might add) one of the properties of resource metadata is that it should have a taxonomy (such as subject, topic, etc getting morespecific) and that this taxonomy can be anywhere from 1 to 16+ layers deep. When it comes to implementing this you have a choice of either a) a single table with a lot of messy SQl statements that takes days to even get close to working, b) 16 tables and only use the ones that are needed, making for either many queries or one heck of an outer join, or c) one field with the taxonomy stored as XML because it supports nesting better than databases.

Also, consider OOP. I once wrote a data saving program for neural networks that could save the entire state of a neural network to a file. Since the network was composed of neurons, connectors, inputs, outputs, layers, etc and needed to be portable I couldn't use a database without making a great number of very specific tables/fields. Using xml however I could save the state of the network without having to determine the actual layout of the network and relationships first. I was then able to rebuild the network through simple for loops as I parsed the data file rather than doing multiple queries to the database and trying to piece back together the relationships before rebuilding the objects. The total save state time, destroy network time, load state time, and instantiate network time was less than 2 seconds for a network with over 200 nodes. In Java.

So while XML wil never be better at saving ER data than an ER database, it has definate advantages in both the communication fields and certain nested data storage areas. With the added advantage that since everyone is agreeing to use it there is no time lost while you try to puzzle your way through someone elses storage technique.

-Tarwn ________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Ok, another reason to use an XML based storage system over a database is: drivers, access and protocols.

With a database, an application needs to be database aware in some way, eg with a connectivity driver such as ODBC or JDBC. Each app has to know how to talk to the db, and know what each of the tables, rows and columns are specifically for that application. This knowledge has to be inbuilt into the code. ODBC and JDBC are bulky and push up code size.

With XML, all I need is an XML parser such as SAX. I can then read any XML document that comes my programs way. I know what tags are specifically for me by all that &quot;useless&quot; meta data that was talked about in a previous post. I know that if I change this document that it will not affect any other programs ability to read it. I can add extra &quot;useless&quot; metadata of my own into the XML document and it still can be read by any other parser.

XML is another tool in a programmers utility belt. Its not better than anything, it has its bad points and good. So do databases.


 
It is very interesting discussion about XML and database. I am pretty new to XML. I would like to explore its advantage as well.

XML seems to be very good at presenting text-rich content. I am wondering what I should use database or XML if I have hundreds of thousands of content (having many sublayers) ? If I use XML, where these content is stored ? Just plain text file ?

 
If you have lots of data I would use a traditional RDBMS to store it and then retrieve that data in XML format. A lot of the major RDBMS's provide functionality to retrieve your data as XML rather than a traditional recordset. This allows easier insertion, update, and deletion, and provides flexability in how you wish to retrieve that data. It also has the advantage of having a much better performance. You can alos apply standard data-integrity on the database level rather than having to build it all into your application.

James :) James Culshaw
james@miniaturereview.co.uk
 
XML seems to be very good at presenting text-rich content. I am wondering what I should use database or XML if I have hundreds of thousands of content (having many sublayers) ? If I use XML, where these content is stored ? Just plain text file ?

XML is a format, not a database.

Yes, you can store XML files on disk, and access them like a database. But it rapidly falls down when you add multi-user access, binary objects, or large numbers of rows. XML on disk is best used for things like program configuration, and sharing files with business partners.

Chip H.
 
Ismail...please understand that XML is just a ***standard encoding specification*** approved by the W3C. That's all it is. It is not a database, a language or anthing like that. Developers use XML around their technology merely for the sole reason of INTEROPERABILITY.

With that said, you can use XML to whatever technology because most likely the technology will support XML. DotNET revolves around XML. So it would be wise to embrace XML if you plan your software to communicate with the rest of the world. Personally, I think it's bloated with metadata and security is a concern to me.
 
XML is also called meta-language, which means that it can describe other languages. XML is neutral, flexible and easier to handle for data exchange. XML is the new standard for databases and World Web, revolutionizes Internet already today. XML is NOT another HTML. The main idea of XML/XSLT is to separate a presentation and content. XML is a best way to store and represent any data in a highly flexible and structured way.
To find out more about how to compare a database and an XML structure you can use a resource like this:
 
Coming from a database background, I must say that databases are much easier to implement on websites than XML. I've been working with XML for a while, and I've noticed that the encoding and decoding specifications for XML can be somewhat mind numbing.

All of the XSLT stuff that you have to go through to get simple records is ridiculous when you consider that a database can find a record based on a SQL statement that is only one line long, where it takes XSLT and XML two or three pages, templates, etc. just to get to the information.

Plus, when using ASP, a database can be communicated with from any platform through web-based forms. So databases are platform independent too. So what's the big deal with XML? You can create your own meta tags? Big deal.
 
I have been working with a content management system that uses both databases and xml. The content is entered and stored into the database, which then publishes it's entire contents to a single xml file.
The advantages of this are manyfold: the database and content management system can be completely separate entities to the website - all the site needs to run is an up-to-date copy of the xml. I have also found that the sites run much quicker using xslt/xml then a database driven website.
Once you get used to xslt/xml you realise how flexible it is, often with one line of xslt reaching the same goal as ten lines of asp would.
Another advantage of a database/xml mix is a &quot;built-in&quot; pre-release function, because changes can be made to the database which will only affect the websites once published to xml.

I guess I'm just trying to say that databases and xml can work hand in hand, with both technologies having definite advantages over the other.

I hope this helps!

Nick (Software Developer)


nick@retrographics.fsnet.co.uk
nick.price@myenable.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top